curl常用的参数配置信息,足以解决温饱

    技术2022-07-10  119

    curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。熟练的话,完全可以取代 Postman 这一类的图形界面工具。

    -v参数输出通信的整个过程,用于调试。

    -A参数指定客户端的用户代理标头,即User-Agent。curl 的默认用户代理字符串是curl/[version]

    -x参数指定 HTTP 请求的代理。

    -X参数指定 HTTP 请求的方法。

    可看到默认为User-Agent为 curl/7.50.3,使用后为Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16

    [Administrator.SKY-20190610AAT] ➤ curl -v www.baidu.com * Rebuilt URL to: www.baidu.com/ * Trying 14.215.177.38... * TCP_NODELAY set * Connected to www.baidu.com (14.215.177.38) port 80 (#0) > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: curl/7.50.3 > Accept: */* > < HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform < Connection: keep-alive < Content-Length: 2381 < Content-Type: text/html < Date: Tue, 30 Jun 2020 14:11:18 GMT < Etag: "588604dc-94d" < Last-Modified: Mon, 23 Jan 2017 13:27:56 GMT < Pragma: no-cache < Server: bfe/1.0.8.18 < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ < <!DOCTYPE html> ....... [Administrator.SKY-20190610AAT] ➤ curl -v -A 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16' www.baidu.com * Rebuilt URL to: www.baidu.com/ * Trying 14.215.177.38... * TCP_NODELAY set * Connected to www.baidu.com (14.215.177.38) port 80 (#0) > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16 > Accept: */* >

    -O参数将服务器回应保存成文件,并将 URL 的最后部分当作文件名.

    -o参数将服务器的回应保存成文件  可指定文件名称

    --limit-rate用来限制 HTTP 请求和回应的带宽,模拟慢网速的环境(可以看到限制为每秒200b时,整个请求响应时间为14s)

    [2020-06-30 22:33.58] ~ [Administrator.SKY-20190610AAT] ➤ curl -v --limit-rate 500b www.baidu.com * Rebuilt URL to: www.baidu.com/ * Trying 14.215.177.39... * TCP_NODELAY set * Connected to www.baidu.com (14.215.177.39) port 80 (#0) > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: curl/7.50.3 > Accept: */* > < HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform < Connection: keep-alive < Content-Length: 2381 < Content-Type: text/html < Date: Tue, 30 Jun 2020 14:34:03 GMT < Etag: "588604dd-94d" < Last-Modified: Mon, 23 Jan 2017 13:27:57 GMT < Pragma: no-cache < Server: bfe/1.0.8.18 < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ < <!DOCTYPE html> <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http://www.baidu.com/?bdorz_come=1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a>  <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号  <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html> * Curl_http_done: called premature == 0 * Connection #0 to host www.baidu.com left intact ✔ ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── [2020-06-30 22:34.12] ~ [Administrator.SKY-20190610AAT] ➤

    -k参数指定跳过 SSL 检测

    -H参数添加 HTTP 请求的标头

    -F参数用来向服务器上传二进制文件

    -d参数可以读取本地文本文件的数据,向服务器发送

    -c参数将服务器设置的 Cookie 写入一个文件

    -b参数用来向服务器发送 Cookie 会读取本地的

    [Administrator.SKY-20190610AAT] ➤ curl -b 'foo1=bar;foo2=bar2' -v www.baidu.com -c cookie * Rebuilt URL to: www.baidu.com/ * Trying 14.215.177.39... * TCP_NODELAY set * Connected to www.baidu.com (14.215.177.39) port 80 (#0) > GET / HTTP/1.1 > Host: www.baidu.com > User-Agent: curl/7.50.3 > Accept: */* > Cookie: foo1=bar;foo2=bar2 > < HTTP/1.1 200 OK < Accept-Ranges: bytes < Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform < Connection: keep-alive < Content-Length: 2381 < Content-Type: text/html < Date: Tue, 30 Jun 2020 14:54:17 GMT < Etag: "588604d8-94d" < Last-Modified: Mon, 23 Jan 2017 13:27:52 GMT < Pragma: no-cache < Server: bfe/1.0.8.18 * Added cookie BDORZ="27315" for domain baidu.com, path /, expire 1593615262 < Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/ < <!DOCTYPE html> <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http://www.baidu.com/?bdorz_come=1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a>  <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号  <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html> * Curl_http_done: called premature == 0 * Connection #0 to host www.baidu.com left intact ✔ ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── [2020-06-30 22:54.22] ~ [Administrator.SKY-20190610AAT] ➤ ll total 19 lrwxrwxrwx 1 Administ UsersGrp 33 Jun 16 2019 Desktop -> /drives/C/Users/ADMINI~1/Desktop/ lrwxrwxrwx 1 Administ UsersGrp 36 Jun 16 2019 LauncherFolder -> /drives/E/PROGRA~1/Mobatek/MOBAXT~1/ lrwxrwxrwx 1 Administ UsersGrp 34 Jun 16 2019 MyDocuments -> /drives/C/Users/ADMINI~1/DOCUME~1/ -rw-r--r-- 1 Administ UsersGrp 12550 Jun 30 22:31 aa.txt -rw-r--r-- 1 Administ UsersGrp 183 Jun 30 22:54 cookie

     

    Processed: 0.009, SQL: 9