【问题标题】:How to cURL post with JSON parameters? [duplicate]如何使用 JSON 参数卷曲帖子? [复制]
【发布时间】:2023-04-09 10:08:01
【问题描述】:

我不确定这是否可行,但我正在尝试卷曲帖子,但使用 json 作为参数,如下所示:

curl -X POST 'https://myserver/action?params={"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}'

但是,我不断收到一些错误curl: (3) [globbing] nested braces not supported at pos X

我该怎么做?

【问题讨论】:

标签: json post curl


【解决方案1】:

有两种方法可以解决这个问题。

  1. 确保您的 JSON 已正确转义,以便可以作为参数发送。
  2. 将 HTTP 标头设置为接受 json。

例如:

curl -X POST -H "Content-Type: application/json" \
--data '{"field1":"something","whatever":10,"description":"body","id":"random","__oh__":{"session":"12345678jhgfdrtyui"}}' \
https://example.com/action

【讨论】:

【解决方案2】:

curl 错误是由于大括号 {} 和方括号 [] 是特殊的 curl 通配符。使用 -g 选项关闭 globbing 应该没问题。

与此帖子相同的问题: How to PUT a json object with an array using curl

【讨论】:

    猜你喜欢
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-22
    • 2022-08-14
    • 1970-01-01
    相关资源
    最近更新 更多