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 <format>

例如我要獲取返回遠程網站的狀態碼以及ip可以這么獲取

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

-m, --max-time <seconds>

          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 <file>

更詳細的請求信息:

-d, --data <data>

使用post發送請求信息

--data-urlencode <data>

對data數據進行編碼

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

-X, --request <command>

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

curl -X POST www.baidu.com

-F, --form <name=content>

上傳文件

如果是文件

-F, --form <name=content>

curl -x 127.0.0.1:8888 -F "web=@output.txt;type=text/html" -F name=xyz url.com

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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容