curl的HTTP参数速查表

757 阅读3分钟

curl简介

curl是一个开源的命令行工具,它基于网络协议,对指定URL进行网络传输,得到数据后不任何具体处理(如:html的渲染等),直接显示在"标准输出"(stdout)上。

curl支持的网络协议有很多,包括:DICT、FILE、FTP、FTPS、GOPHER、GOPHERS、HTTP、HTTPS、IMAP、IMAPS、LDAP、LDAPS、MQTT、POP3、POP3S、RTMP、RTMPS、RTSP、SCP、SFTP、SMB、SMBS、SMTP、SMTPS、TELNET和TFTP。

curl的参数也有很多,以下主要介绍HTTP和HTTPS相关的参数,建议收藏保存。

参数速查表

参数描述示例
-A, --user-agent 发送指定的User-Agent到服务端curl -A "Agent 007" one.more
--alt-svc 使用此缓存文件启用alt-svccurl --alt-svc svc.txt one.more
--anyauth选择任意认证方法curl --anyauth --user me:pwd one.more
--compressed请求压缩 (使用 deflate 或 gzip)curl --compressed one.more
-b, --cookie <datafilename>发送cookie的字符串,或者读取发送cookie的文件位置curl -b cookies.txt one.more
-c, --cookie-jar 操作结束后写入cookie到指定的文件curl -c cookies.txt one.more
-d, --data HTTP POST 的数据curl -d "name=onemore" one.more
--data-ascii HTTP POST 的ASCII数据curl --data-ascii @file one.more
--data-binary HTTP POST 的二进制数据curl --data-binary @file one.more
--data-raw HTTP POST 的数据(不对@字符做特殊解析)curl --data-raw "one@more" one.more
--data-urlencode HTTP POST 的url编码的数据curl --data-urlencode name=onemore one.more
--digest使用HTTP摘要访问认证curl -u name:password --digest one.more
--disallow-username-in-url禁止在url中输入用户名curl --disallow-username-in-url one.more
-D, --dump-header 把接收到的header写入到指定的文件curl --dump-header header.txt one.more
-e, --referer 指定Referrer的URLcurl --referer "more.one" one.more
--etag-compare 从文件中读取作为header中的ETagcurl --etag-compare etag.txt one.more
--etag-save 从请求中解析ETag并将其保存到指定的文件中curl --etag-save etag.txt one.more
--expect100-timeout 允许等待100-continue响应的最大时间(以秒为单位)curl --expect100-timeout 2.5 one.more
-f, --fail在服务器出错时不显示HTTP错误信息curl --fail one.more
-F, --form <name=content>模拟用户按下提交表单curl -F image=@onemore.jpg one.more
--form-string <name=string>模拟用户按下提交表单(值为字符串)curl --form-string "data" one.more
-G, --get将POST数据放在URL中并发起GET请求curl --get -d "name=onemore" one.more
--haproxy-protocol发送HAProxy PROXY v1的headercurl --haproxy-protocol one.more
-i, --include在输出中包含HTTP响应头curl -i one.more
-I, --head只显示响应头信息curl -I one.more
-H, --header header/@file发送自定义headercurl -H "Content-Type: application/json;charset=UTF-8" one.more
--hsts 启用HSTS进行传输curl --hsts cache.txt one.more
--http0.9使用HTTP 0.9curl --http0.9 one.more
-0, --http1.0使用HTTP 1.0curl --http1.0 one.more
--http1.1使用HTTP 1.1curl --http1.1 one.more
--http2使用HTTP 2curl --http2 one.more
--http2-prior-knowledge使用HTTP 2(不使用HTTP/1.1 Upgrade)curl --http2-prior-knowledge one.more
--http3使用HTTP 3curl --http3 one.more
--ignore-content-length忽略服务端资源的大小curl --ignore-content-length one.more
-j, --junk-session-cookies忽略从文件中读取的会话cookiecurl --junk-session-cookies -b cookies.txt one.more
-L, --location启用重定向curl --L one.more
--location-trusted启用重定向并发送验证信息到其它主机curl --location-trusted -u user:pwd one.more
--max-redirs 重定向的最大次数curl --max-redirs 3 --location one.more
--negotiate使用HTTP Negotiate (SPNEGO) 认证curl --negotiate -u : one.more
--no-alpn禁用ALPN TLS扩展curl --no-alpn one.more
--no-npn禁用NPN TLS扩展curl --no-npn one.more
--ntlm使用HTTP NTLM认证curl --ntlm -u user:pwd one.more
--ntlm-wb使用HTTP NTLM认证(使用ntlmauth程序做身份验证)curl --ntlm-wb -u user:pwd one.more
--post301在301重定向后不切换为 GET 请求curl --post301 --location one.more
--post302在302重定向后不切换为 GET 请求curl --post302 --location one.more
--post303在303重定向后不切换为 GET 请求curl --post303 --location one.more
-r, --range 只接收范围内的字节curl --range 22-44 one.more
--raw禁用所有内部HTTP对内容或传输编码的解码curl --raw one.more
--tr-encoding请求压缩传输编码算法,并解压接收到的数据curl --tr-encoding one.more
-v, --verbose显示通信的整个过程,包括端口连接和头信息。curl -v one.more
-z, --time-cond 请求在给定时间之后或之前被修改的文件curl -z "Tue 18 Jan 2021 13:14:15" one.more

curl 版本号:7.74.0


竟然已经看到这里了,你我定是有缘人,留下你的点赞关注,他日必成大器。