我有以下cURL请求。我想获取http_code,但我想要一个不同的变量,否则它会解析来自GET调用的JSON响应。获取卷曲http代码
有没有办法做到这一点?
curl --write-out %{http_code} --silent --output GET --header "Accept: application/json" --header "URL"
我有以下cURL请求。我想获取http_code,但我想要一个不同的变量,否则它会解析来自GET调用的JSON响应。获取卷曲http代码
有没有办法做到这一点?
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
卷曲-i -H “接受:应用/ JSON”, “服务器:5050/A/C /的getName {” 参数0 “:” Arvind的 “}”
这就像运行定期卷曲请求。 –
卷曲-w 'RESP_CODE:%{RESPONSE_CODE}' -s -X POST --data '{ “ASDA”: “ASD”}' http://example.com --header“内容类型:application/json“| grep -o'RESP_CODE:[1-4] [0-9] [0-9]'
我需要响应代码和实际的JSON响应 –
response = $(卷曲-sb -H“接受:应用/ JSON”“http://host:8080/some/resource”)为响应只是尝试$响应
试试这个下面可能是能帮助您找到解决https://gist.github.com/sgykfjsm/1dd9a8eee1f70a7068c9
我也需要实际的输出。这是否给我输出和状态代码? –
这只是将状态代码附加到JSON响应的末尾。 –
但是你有'--output/dev/null'这是抑制所有的输出。 – anubhava