curl命令总结
在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具。它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具。
1、-x
-x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port --proxy-anyauth Pick "any" proxy authentication method (H) --proxy-basic Use Basic authentication on the proxy (H) --proxy-digest Use Digest authentication on the proxy (H) --proxy-negotiate Use HTTP Negotiate (SPNEGO) authentication on the proxy (H) --proxy-ntlm Use NTLM authentication on the proxy (H) --proxy-service-name NAME SPNEGO proxy service name --service-name NAME SPNEGO service name
-x/--proxy host[:port] 在给定的端口上使用HTTP代理
curl -x 127.0.0.1:端口 域名 #将域名解析到本机某个域名的某个端口
适用:适用于域名解析到负载均衡,后端某个服务器上执行测试。
2、-X
-X, --request COMMAND Specify request command to use --resolve HOST:PORT:ADDRESS Force resolve of HOST:PORT to ADDRESS --retry NUM Retry request NUM times if transient problems occur --retry-delay SECONDS Wait SECONDS between retries --retry-max-time SECONDS Retry only within this period --sasl-ir Enable initial response in SASL authentication
用法1:发送POST请求
curl -X POST -d 'post content' URL
注意:-d 选项后的内容强烈建议用单引号'包含起来,而非双引号。
3、-L
-L, --location Follow redirects (H) --location-trusted Like '--location', and send auth to other hosts (H) --login-options OPTIONS Server login options (IMAP, POP3, SMTP)
用法1:curl -L ip.cn #查看服务器本机外网IP
用法2:自动跳转
有的网址是自动跳转的。使用 -L
参数,curl 就会跳转到新的网址。
$ curl -L www.sina.com
4、-H -H/--header <header> 指定请求头参数
-H, --header LINE Pass custom header LINE to server (H)
利用-H传递参数给服务器,如post请求时,传递Authorization给服务器
curl
5、-i
-i
参数可以显示 http response 的头信息,连同网页代码一起。-I
参数则只显示 http response 的头信息。
6、-v
-v/--verbose 小写的v参数,用于打印更多信息,包括发送的请求信息,这在调试脚本是特别有用。
7、-d
-d/--data/--data-ascii <data>
您的资助是我最大的动力!
金额随意,欢迎来赏!