spring mvc restfull webservice handle post method“415 Unsupported Media Type”

时间:2014-02-03 13:15:30

标签: spring rest

@Controller
public class Mycontroller {
@RequestMapping(method = RequestMethod.GET,value="/insertAdminUserInfo")
public void insertPerformanceInfo(HttpServletRequest request, Model model) throws Exception {
  String userId = (String) request.getParameter("user");
  String region = (String) request.getParameter("status");
  //my business logic
  model.addAttribute("result","success");

}
@RequestMapping(value="/insertAdminUserInfo",method=RequestMethod.POST)
public void insertPerformanceInfoPOST(@RequestBody UserInfo userInfo, Model model) throws Exception {
 //my business logic
model.addAttribute("result","success");
}
@RequestMapping(value="/insertAdminUserInfo",method=RequestMethod.PUT)
public void insertPerformanceInfoPUT(@RequestBody UserInfo userInfo, Model model) throws Exception {
//my business logic
model.addAttribute("result","success");
}
}

这是我的代码,我正在尝试使用POST或PUT方法通过SOAP UI或REst Client发送json数据,我收到以下错误。

仅供参考:GET方法正常工作。

Response Header:
Status Code: 415 Unsupported Media Type 
    Connection: Close 
Content-Language: en-US 
Content-Type: text/html;charset=utf-8 
Date: Mon, 03 Feb 2014 12:34:44 GMT 
Server: WebSphere Application Server/7.0 
Transfer-Encoding: chunked </br>

回应机构:

错误415:SRVE0295E:报告错误:415

请提出一些建议。

此致 Vasanth D

2 个答案:

答案 0 :(得分:1)

您的 Content-Type 标头与媒体类型不匹配。

例如,如果您向服务发送JSON正文,则内容类型应为:

Content-Type: application/json

答案 1 :(得分:0)

注释&#34; RequestBody&#34;期望 Content-Type 为&#34; application / json &#34;。因此,在调用api之前,请务必设置 Content-Type