gpt4 book ai didi

bash - 获取 curl http 代码

转载 作者:可可西里 更新时间:2023-11-01 17:05:47 25 4
gpt4 key购买 nike

我有以下 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

关于bash - 获取 curl http 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44335839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com