我几周前就开始工作了,但是在对我的网络服务进行了一些更改后它停止了工作
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody String addComplaint(@RequestBody Complaint complaint) {
......
}
curl -i -H "content-type: application/json" -X POST -d '{"var1":"data1","var2":"data2"}' http://server:8080/api/complaint/add
以下是我得到的
HTTP/1.1 415 Unsupported Media Type
Pragma: no-cache
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1408
Server: Jetty(8.1.8.v20121106)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 415 Unsupported Media Type</title>
</head>
<body><h2>HTTP ERROR 415</h2>
<p>Problem accessing /api/complaint/add. Reason:
<pre> Unsupported Media Type</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
</body>
</html>
我有时会遇到这个错误,我通过设置标题来解决它,即httpPost.setHeader(“accept”,“application / json”),httpPost.setHeader(“content-type”,“application / json”); 但在对我的网络服务进行更改后,它无法再次运行。 curl命令给了我上面的输出。 任何帮助将受到高度赞赏
答案 0 :(得分:0)
您的请求可能缺少接受标头试试这个:
curl -i -H "content-type: application/json" -H "Accept: application/json" -X POST -d '{"var1":"data1","var2":"data2"}' http://server:8080/api/complaint/add