无法在Windows中使用curl POST json数据

Fot*_*isK 7 json curl

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

我尝试了 \" 或 """ 什么也没有。json数据:

{
    "frames": [
        {
            "text": "HOME2",
            "icon": "i294",
            "index": 0
        },
        {
            "text": "? 65",
            "icon": null,
            "index": 1
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

卷曲尝试的示例:

> 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
Run Code Online (Sandbox Code Playgroud)

和 \”

> 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
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Fot*_*isK 3

因此,在进一步阅读并根据 mohsen 的回答后,我将命令行最终确定为:

curl -H "Accept: application/json" -H "X-Access-Token: xyz" -X POST "https://xyz" -d @exported.json
Run Code Online (Sandbox Code Playgroud)

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

json 数据本身不需要太多调整,请参阅exported.json 文件:

{"frames":[{"text":"HOME2","icon":"i294","index":"0"},{"text":"? 65","icon":"null","index":"1"}]}
Run Code Online (Sandbox Code Playgroud)