【发布时间】:2019-03-30 13:03:55
【问题描述】:
我正在尝试将 JSON 输出从一个 curl 流式传输到另一个 curl 的数据参数中。可能吗?
第一步:例如输出JSON的curl为:
curl -sG api.com/test -H "Authorization: Bearer ${token}" | jq '.[] | select(.query|test("latency")) | @json'
返回:
"{\"query\":\"origin == 'router' and name == 'latency'\",\"threshold\":{\"critical\":65000,\"warning\":55000,\"type\":\"UPPER\"}}"
第 2 步:如果我在第二个 curl 中使用第一个 curl 的输出,我有一个成功的响应:
curl -v "api.com/test" --data "{\"query\":\"origin == 'router' and name == 'latency'\",\"threshold\":{\"critical\":20000,\"warning\":15000,\"type\":\"UPPER\"}}" -H "Authorization: Bearer ${token}" -H "Content-Type: application/json"
成功响应:
{
"query" : "origin == 'router' and name == 'latency'",
"threshold" : {
"critical" : 20000.0,
"type" : "UPPER",
"warning" : 15000.0
}
}
第 1 步和第 2 步合并:我正在尝试将这两个步骤合并为一个,如下所示:
curl -sG hapi.com/test -H "Authorization: Bearer ${token}" | jq '.[] | select(.query|test("latency")) | @json' | curl -d @- -H "Authorization: Bearer ${token}" -H "Content-Type: application/json" "api.com/test"
但是不断收到错误的请求:
{
"timestamp" : 1553950852034,
"status" : 400,
"error" : "Bad Request",
"exception" : "org.springframework.http.converter.HttpMessageNotReadableException",
"message" : "Bad Request",
"path" : "/test"
}
可能吗?
【问题讨论】:
-
INSTANCE_REGION=$(curl -sG api.com/test -H "授权:承载 ${token}" | jq '.[] | select(.query|test("latency")) | @json') | curl -v "api.com/test" --data $INSTANCE_REGION -H "Authorization: Bearer ${token}" -H "Content-Type: application/json"
-
返回
HTTP/1.1 401 Unauthorized。 -
必须是您的身份验证标头。
-
也许吧。我确实确保令牌是有效的。
-
您是否尝试过不将
select过滤器的输出通过管道传输到@json?
标签: json bash curl input stream