相关疑难解决方法(0)

如何使用Curl从终端/命令行发布JSON数据到测试Spring REST?

我使用Ubuntu并在其上安装了Curl.我想用Curl测试我的Spring REST应用程序.我在Java端编写了我的POST代码.但是,我想用Curl测试它.我正在尝试发布JSON数据.示例数据如下:

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

我用这个命令:

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

它返回此错误:

HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1051
Date: Wed, 24 Aug 2011 08:50:17 GMT
Run Code Online (Sandbox Code Playgroud)

错误描述如下:

服务器拒绝此请求,因为请求实体的格式不受所请求方法()的请求资源支持.

Tomcat日志:"POST/ui/webapp/conf/clear HTTP/1.1"415 1051

关于Curl命令的正确格式的任何想法?

编辑:

这是我的Java端PUT代码(我测试过GET和DELETE,它们有效)

@RequestMapping(method = RequestMethod.PUT)
public Configuration updateConfiguration(HttpServletResponse response, @RequestBody Configuration configuration) { //consider @Valid tag
    configuration.setName("PUT worked");
    //todo If error occurs …
Run Code Online (Sandbox Code Playgroud)

rest json curl spring-mvc http-headers

2606
推荐指数
24
解决办法
263万
查看次数

标签 统计

curl ×1

http-headers ×1

json ×1

rest ×1

spring-mvc ×1