簡體   English   中英

獲取curl http代碼

[英]Get curl http code

我有以下cURL請求。 我想獲取http_code,但是我想要一個不同的變量,因為否則它將與解析GET調用中的JSON響應混淆。

反正有這樣做嗎?

curl --write-out %{http_code} --silent --output GET --header "Accept: application/json" --header "URL"

只需使用命令替換將狀態代碼存儲在變量中:

status=$(curl --write-out %{http_code} --silent --output tmp.out GET --header "Accept: application/json" --header "URL")
data=$(<tmp.out)

# check status now
declare -p status

# check data
declare -p data

curl -i -H“接受:應用程序/ json”“服務器:5050 / a / c / getName {” param0“:” Arvind“}”

curl -w'RESP_CODE:%{response_code}'-s -X POST --data'{“ asda”:“ asd”}' http://example.com --header“ Content-Type:application / json” | grep -o'RESP_CODE:[1-4] [0-9] [0-9]'

response = $(curl -sb -H“ Accept:application / json”“ http:// host:8080 / some / resource ”)對於響應,只需嘗試$ response

請嘗試以下操作,這可能會幫助您找到解決方案https://gist.github.com/sgykfjsm/1dd9a8eee1f70a7068c9

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM