最佳答案
我使用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}
我使用这个命令:
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
它返回此错误:
HTTP/1.1 415 Unsupported Media TypeServer: Apache-Coyote/1.1Content-Type: text/html;charset=utf-8Content-Length: 1051Date: Wed, 24 Aug 2011 08:50:17 GMT
错误描述是这样的:
服务器拒绝了此请求,因为请求实体的格式不受所请求方法()的请求资源的支持。
Tomcat日志:"POST/用户界面/webapp/conf/Clear HTTP/1.1"415 1051
cURL命令的正确格式是什么?
这是我的Java代码(我已经测试了GET和DELETE,它们可以工作):
@RequestMapping(method = RequestMethod.PUT)public Configuration updateConfiguration(HttpServletResponse response, @RequestBody Configuration configuration) { //consider @Valid tagconfiguration.setName("PUT worked");//todo If error occurs response.sendError(HttpServletResponse.SC_NOT_FOUND);return configuration;}