curl学习记录

-s, —slient

沉默模式, 不显示具体的过程, 看一下有没有这个参数的区别

xyz@mac:~ > curl -o /dev/null www.baidu.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 96551    0 96551    0     0  58649      0 --:--:--  0:00:01 --:--:-- 58657
xyz@mac:~ > curl -o /dev/null -s www.baidu.com
xyz@mac:~ >

-w, --write-out

例如我要获取返回远程网站的状态码以及ip可以这么获取

curl -o /dev/null -s -w %{http_code}:%{remote_ip} www.baidu.com

-m, --max-time

          Maximum time in seconds that you allow the whole operation to take. 设置超时时间

> curl www.google.com.hk -m 1
curl: (28) Connection timed out after 1003 milliseconds

-x, --proxy <[protocol://][user:password@]proxyhost[:port]>

          Use the specified proxy. 使用代理

-i, --include

          (HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...

获取的内容包括响应头

-I, --head

          (HTTP/FTP/FILE)  Fetch  the HTTP-header only! HTTP-servers feature the command HEAD which this uses to get nothing but the header of a document. When used on an FTP or FILE file, curl dis-

          plays the file size and last modification time only.

只获取http响应头, 使用http的HEAD方法请求

curl -x 127.0.0.1:8888 -I www.baidu.com

-L, --location

自动跳转

curl -I -L baidu.com/a

-v, --verbose

获取通信的详细过程

--trace

更详细的请求信息:

-d, --data

使用post发送请求信息

--data-urlencode

对data数据进行编码

curl -x 127.0.0.1:8888 --data "q=apple" http://dict.youdao.com/search

-X, --request

使用不同的请求方式, 例如使用post方式请求baidu

curl -X POST www.baidu.com

-F, --form

上传文件

如果是文件

-F, --form

curl -x 127.0.0.1:8888 -F "[email protected];type=text/html" -F name=xyz url.com

—header, —referer, —cookie, —user-agent 都看字面意思就知道作用了

你可能感兴趣的:(curl学习记录)