简体   繁体   English

415不支持的媒体类型与Angular JS

[英]415 unsupported media type With Angular JS

Spring code 弹簧码

@RequestMapping(value="/users",method=RequestMethod.POST,headers = "content-type=application/json;application/x-www-form-urlencoded; charset=UTF-8")
public @ResponseBody String addNewCinemaCampaign( @RequestBody @Valid User user)
{
    System.out.println(user!=null?user.getName():"Null");
    return userService.createUser(user);
}

I am creating new user via Angular post method but I am getting always 415 unsupported media type. 我正在通过Angular post方法创建新用户,但我总是得到415种不受支持的媒体类型。 Please resolve this problem... 请解决此问题...

I think it will be helpful in your case: 我认为这对您的情况会有所帮助:

produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE

So in your code it will be 所以在你的代码中

@RequestMapping(value="/users",method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String addNewCinemaCampaign( @RequestBody @Valid User user)
{
    System.out.println(user!=null?user.getName():"Null");
    return userService.createUser(user);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM