gpt4 book ai didi

json - 无法在 Windows 中使用 curl 发布 json 数据

转载 作者:行者123 更新时间:2023-12-05 02:54:47 25 4
gpt4 key购买 nike

我已经阅读了几篇关于这个主题的文章,但我无法弄清楚如何在 Windows 10 (powershell) 上使用 curl POST 发送 json 数据。

我没有尝试使用\"或 """。json数据:

{
"frames": [
{
"text": "HOME2",
"icon": "i294",
"index": 0
},
{
"text": "? 65",
"icon": null,
"index": 1
}
]
}

curl 尝试示例:

> curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d "{ """frames""": [{ """text""": """HOME2""", """icon""": """i294""", """index""": 0 }, { """text""": """? 65""", """icon""": null, """index""": 1 }]}"
{"error":{"code":null,"message":"Bad Request","trace":["request body must not be empty"]}}curl: (3) [globbing] bad range specification in column 2
curl: (6) Could not resolve host: text
curl: (6) Could not resolve host: HOME2,
curl: (6) Could not resolve host: icon
curl: (6) Could not resolve host: i294,
curl: (6) Could not resolve host: index
curl: (6) Could not resolve host: 0
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: text
curl: (6) Could not resolve host: ? 65,
curl: (6) Could not resolve host: icon
curl: (6) Could not resolve host: null,
curl: (6) Could not resolve host: index
curl: (6) Could not resolve host: 1
curl: (3) [globbing] unmatched close brace/bracket in column 1

与\"

> curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d "{ \"frames\": [ { \"text\": \"HOME2\", \"icon\": \"i294\", \"index\": 0 }, { \"text\": \"? 65\", \"icon\": null, \"index\": 1 } ] }"
{"error":{"code":null,"message":"Bad Request","trace":["request body must not be empty"]}}curl: (3) [globbing] bad range specification in column 2
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: \text\
curl: (6) Could not resolve host: \HOME2\,
curl: (6) Could not resolve host: \icon\
curl: (6) Could not resolve host: \i294\,
curl: (6) Could not resolve host: \index\
curl: (6) Could not resolve host: 0
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: \text\
curl: (6) Could not resolve host: \? 65\,
curl: (6) Could not resolve host: \icon\
curl: (6) Could not resolve host: null,
curl: (6) Could not resolve host: \index\
curl: (6) Could not resolve host: 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1

我做错了什么?

最佳答案

因此,在进一步阅读和从 mohsen 的回答中,我最终确定了我的命令行:

curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d @exported.json

我将 json 添加到一个名为 exported.json 的文件中,现在它更紧凑并且仍然有效。

它自己的 json 数据不需要太多调整,请参阅 exported.json 文件:

{"frames":[{"text":"HOME2","icon":"i294","index":"0"},{"text":"? 65","icon":"null","index":"1"}]}

关于json - 无法在 Windows 中使用 curl 发布 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61624448/

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