你的cURL命令格式不正确,应该将JSON数据放在请求体中,而不是作为URL参数。正确的cURL命令如下:
curl -i \
-H "Accept: application/json" \
-H "X-HTTP-Method-Override: PUT" \
-X POST -d '{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}' \
http://localhost:8080/xx/xxx/xxxx
注意,我将JSON数据用单引号括起来,并将其放在-d
参数的末尾。这样,cURL会将JSON数据作为请求体发送给服务器。
你需要将你的Content-Type设置为application/json。但是-d
(或--data
)默认发送Content-Type为application/x-www-form-urlencoded
,Spring端不接受这个类型。
查看curl手册页,我认为你可以使用-H
(或--header
):
-H "Content-Type: application/json"
完整示例:
curl --header "Content-Type: application/json" \
--request POST \
--data '{"username":"xyz","password":"xyz"}' \
http://localhost:3000/api/login
(-H
是--header
的缩写,-d
是--data
的缩写)
注意,如果你使用了-d
,则可选使用-request POST
,因为-d
标志暗示了POST请求。
在Windows上,情况略有不同。请参见注释线程。