curl傳送請求,配置cookie Head等引數

2021-10-09 00:25:25 字數 2916 閱讀 4800

cmd視窗,可通過curl指令,直接傳送http 請求(預設為get請求):

配置請求的cookie:

配置請求頭的引數:

curl傳送post請求:

curl -x post "http://localhost:3355/actuator/refresh"
curl常用引數:

# 除錯類

-v, --verbose 輸出資訊

-q, --disable 在第乙個引數位置設定後 .curlrc 的設定直接失效,這個引數會影響到 -k, --config -a, --user-agent -e, --referer

-k, --config file 指定配置檔案

-l, --location 跟蹤重定向 (h)

# cli顯示設定

-s, --silent silent模式。不輸出任務內容

-s, --show-error 顯示錯誤. 在選項 -s 中,當 curl 出現錯誤時將顯示

-f, --fail 不顯示 連線失敗時http錯誤資訊

-i, --include 顯示 response的header (h/f)

-i, --head 僅顯示 響應文件頭

-l, --list-only 只列出ftp目錄的名稱 (f)

-#, --progress-bar 以進度條 顯示傳輸進度

# 資料傳輸類

-x, --request [get|post|put|delete|…] 使用指定的 http method 例如 -x post

-e, --referer 設定 referer (h)

--data-raw ascii 編碼 http post 資料 (h)

--data-binary binary 編碼 http post 資料 (h)

--data-urlencode url 編碼 http post 資料 (h)

-g, --get 使用 http get 方法傳送 -d 資料 (h)

-f, --form 模擬 http 表單資料提交 multipart post (h)

--form-string 模擬 http 表單資料提交 (h)

-u, --user 使用帳戶,密碼 例如 admin:password

-b, --cookie cookie 檔案 (h)

-j, --junk-session-cookies 讀取檔案中但忽略會話cookie (h)

-a, --user-agent user-agent設定 (h)

# 傳輸設定

-c, --continue-at offset 斷點續轉

-x, --proxy [protocol://]host[:port] 在指定的埠上使用**

-u, --proxy-user user[:password] **使用者名稱及密碼

# 檔案操作

-t, --upload-file 上傳檔案

# 輸出設定

-o, --output 將輸出寫入檔案,而非 stdout

-o, --remote-name 將輸出寫入遠端檔案

-d, --dump-header 將頭資訊寫入指定的檔案

-c, --cookie-jar 操作結束後,要寫入 cookies 的檔案位置

curl更多指令引數可以看看阮一峰老師的用法指南

curl傳送請求總結

經常要用到curl,需要呼叫被人的介面,總結了乙個好用的方法,下次直接用 2 設定提交方式 switch type 3 裝置請求體 if count body 0 設定請求頭 if count header 0 上傳檔案相關設定 curl setopt ch,curlopt followlocati...

PHP 傳送cURL請求

desc xmsb curl 傳送curl請求 param string url 請求位址 param array data post請求的引數 param array header 頭部資訊 return string function xmsb curl url,data header 為1時返...

curl模擬傳送post請求

curl模擬傳送post請求 初始化 curl curl init 設定抓取的url curl setopt curl,curlopt url,設定標頭檔案的資訊作為資料流輸出 curl setopt curl,curlopt header,1 設定獲取的資訊以檔案流的形式返回,而不是直接輸出。cu...