- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業(yè)務(wù)經(jīng)營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯(lián)網(wǎng)協(xié)會理事單位
- 安全聯(lián)盟認(rèn)證網(wǎng)站身份V標(biāo)記
- 域名注冊服務(wù)機(jī)構(gòu)許可:滇D3-20230001
- 代理域名注冊服務(wù)機(jī)構(gòu):新網(wǎng)數(shù)碼
在網(wǎng)絡(luò)請求與數(shù)據(jù)交互領(lǐng)域,curl 憑借其輕量、靈活的特性成為開發(fā)者與運(yùn)維人員的必備工具。無論是日常接口調(diào)試、文件傳輸,還是復(fù)雜的性能分析,curl 都能通過豐富的參數(shù)組合實(shí)現(xiàn)高效操作。本文以 2025 年 3 月 10 日為時(shí)間背景,系統(tǒng)梳理 curl 的 10 類高頻使用場景,結(jié)合實(shí)例與輸出示例,幫助大家快速掌握其核心用法。
curl -i "http://www.tjdsmy.cn/uacserver/user/personalsettings?userId=20722351"
HTTP/1.1 200
Server: nginx/1.13.7
Date: Tue, 10 Oct 2023 02:45:37 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
processId: dc5a8a60-d37b-4e87-b111-dd6eab484b17
upstream_http_reqid: dc5a8a60-d37b-4e87-b111-dd6eab484b17
processTime: 4
upstream_http_time: 4
…… 數(shù)據(jù)內(nèi)容
curl -i -X POST -d 'data={"timenewsID":"1447","shareScope":{"type":"0","scope_id":[0]}}' 'http://www.tjdsmy.cn/microblog/timenews/modifysharescope?user_id=62051317&session_id=2dc60ccf24a6088a1e6a638205ed5f66f11dac97'
curl -i -X POST -F "user_id=1453280&session_id=61f730d921eed96d88f34cb18d0e592d6f21202b" 'http://www.tjdsmy.cn/uccserver/uccapi/user/check'
curl --data-urlencode "value& 1" http://www.tjdsmy.cn
curl -i -X POST -H "Content-Type: application/json" -d "{"newid":"1447"}'" 'http://www.tjdsmy.cn/microblog/timenews/timenewpraise/1447'
curl -O http://www.tjdsmy.cn/software/gettext/manual/gettext.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1556k 100 1556k 0 0 121k 0 0:00:12 0:00:12 --:--:-- 135k
curl -o mygettext.html http://www.tjdsmy.cn/software/gettext/manual/gettext.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1556k 100 1556k 0 0 164k 0 0:00:09 0:00:09 --:--:-- 182k
curl -F "userId=88407056" -F "file=@mygettext.html" "http://www.tjdsmy.cn/eamsgateway/eams-support/setting/uploadFile"
curl -v -F "file=@mygettext.html" "http://www.tjdsmy.cn/eamsgateway/eams-support/setting/uploadFile"
* Trying 10.255.0.71...
* TCP_NODELAY set
* Connected to testweb.quanshi.com (10.255.0.71) port 80 (#0)
> POST /eamsgateway/eams-support/setting/uploadFile HTTP/1.1
> Host: testweb.quanshi.com
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Length: 1594364
> Content-Type: multipart/form-data; boundary=------------------------3fa4d90f3c8f29f3
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 10 Oct 2023 04:57:30 GMT
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< Vary: Accept-Encoding
< Access-Control-Allow-Methods: POST,GET,OPTIONS,DELETE
< Access-Control-Max-Age: 3600
< Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin,Accept,cache-control,if-modified-since
< Set-Cookie: JSESSIONID=F6921C9D1FADEA898E2BD5B9C935E4A8; Path=/; HttpOnly
<
* Connection #0 to host testweb.quanshi.com left intact
…… 響應(yīng)body
* Closing connection 0
curl -x proxy.com:3128 http://www.tjdsmy.cn
curl -o /dev/null -s -w "\\nhttp_code: %{http_code}\\ntime_namelookup: %{time_namelookup}s\\ntime_connect: %{time_connect}s\\ntime_starttransfer: %{time_starttransfer}s\\ntime_total: %{time_total}s\\n" "http://www.tjdsmy.cn/umsapi/rs/users/64042216/organizations"
time_namelookup: %{time_namelookup}s\\n
time_connect: %{time_connect}s\\n
time_appconnect: %{time_appconnect}s\\n
time_redirect: %{time_redirect}s\\n
time_pretransfer: %{time_pretransfer}s\\n
time_starttransfer: %{time_starttransfer}s\\n
----------\\n
time_total: %{time_total}s\\n
curl -s -o /dev/null -w "@curl-format.txt" "http://www.tjdsmy.cn/umsapi/rs/users/64042216/organizations"
time_namelookup: 0.002610s
time_connect: 0.022759s
time_appconnect: 0.000000s
time_redirect: 0.000000s
time_pretransfer: 0.022797s
time_starttransfer: 0.050744s
----------
time_total: 0.050963s
掌握 curl 的多樣化指令,不僅能提升開發(fā)效率,更能深入理解 HTTP 協(xié)議細(xì)節(jié)。從基礎(chǔ)的請求構(gòu)造到高級的耗時(shí)分析,本文通過典型案例展現(xiàn)了 curl 的強(qiáng)大功能。在實(shí)際應(yīng)用中,建議結(jié)合具體場景靈活組合參數(shù),同時(shí)關(guān)注輸出中的響應(yīng)頭、狀態(tài)碼及性能指標(biāo),以實(shí)現(xiàn)精準(zhǔn)的問題定位與優(yōu)化。期待這些實(shí)用技巧能成為工具箱中的利刃。
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP