curl 给出错误,而邮递员按预期工作“无法解码 JSON 对象:期望用双引号括起来的属性名称”

问题描述 投票:0回答:1

当我给出以下curl命令(以及下面的各种其他格式)时,我不断遇到错误,但是它用Postman很好地发布:

curl --location "http://localhost:5000/user/signup" --header "Content-Type:application/json" --data-raw "{ "name":"Raj Kumar","email":"[email protected]","password":"samplepassword" }"

curl --location "http://127.0.0.1:5000/user/signup" --header "Content-Type: application/json" --data-raw '{ "name": "Raj Kumar", "email": "[email protected]", "password": "samplepassword" }'

我得到的错误:

Failed to decode JSON object: Expecting property name enclosed in double quotes: line 1 column 3 (char 2) 

curl: (3) unmatched close brace/bracket in URL position 53: 

Kumar,email:[email protected],password:samplepassword }

curl: (3) URL using bad/illegal format or missing URL

邮递员:
enter image description here

我多次尝试格式化代码,但似乎不起作用。我也尝试过将双引号换成单引号。

我期待与下面的 Postman 相同的输出:

python flask curl postman
1个回答
0
投票

问题是Json中的双引号。 在 Json 周围使用单引号,并在其中使用双引号即可:

curl --location "http://localhost:5000/user/signup" --header "Content-Type: application/json" --data-raw '{ "name":"Raj Kumar","email":"[email protected]","password":"samplepassword" }' 

© www.soinside.com 2019 - 2024. All rights reserved.