gpt4 book ai didi

bash - 将 cURL 响应重定向到 POST 的 cURL,但不通过文件

转载 作者:行者123 更新时间:2023-12-02 16:43:20 25 4
gpt4 key购买 nike

我想将一个 json 对象从一个 url(json) 直接发布到另一个 url

所以命令如下:

curl "<resource_link>.json" -o sample.json
curl -X POST "<my_link>" "Content-type: application/json" -d @sample.json

我想避免这种情况,那么解决方案是什么?是这样的吗?

curl -X POST "<my_link>" "Content-type: application/json" -d "curl <resource_link>.json" 

但是没有效果?还有,这篇文章Stream cURL response to another cURL command posting the result没有彻底解释并且它不起作用是的,

curl

手册解释了“@”,但没有解释如何使用另一个 curl或者,如果我可以在某个地方临时保存第一个 cURL 响应并在另一个命令中使用它(但不在文件中)

最佳答案

  1. 想要 -x POST 在那里,所以让我们从删除它开始吧。
  2. 通过使用-o 或告诉-o 使用带有 的stdout 将第一次传输的结果发送到stdout -o-,和
  3. 使用 -d@- 确保您的第二次传输接受要在 stdin 上发送的数据。
curl "<link>.json" | curl "<link2>" -H "Content-type: application/json" -d @-

使用 curl 7.82.0 及更高版本

从 curl 7.82.0 开始,您可以使用新的 --json 选项更轻松地完成此操作:

curl "<link>.json" | curl "<link2>" --json @-

关于bash - 将 cURL 响应重定向到 POST 的 cURL,但不通过文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61119099/

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