[英]415 (Unsupported Media Type)
while using POST using angularJS to the rest based controller in Spring MVC, I am getting 415 Media Type unsupported type. 在Spring MVC中将AngularJS的POST使用到基于其余的控制器时,我得到了415 Media Type不支持的类型。 Can anybody please help in fixing the same.Below is the code for angularJS and Rest based controller.
任何人都可以帮助修复它。以下是基于angularJS和Rest的控制器的代码。
AngularJS- AngularJS-
$http.post(urlBase + 'users/insert',$scope.user)
.success(function(data) {
$scope.users = data;
$scope.user="";
$scope.toggle='!toggle';
});
Controller rest based - 基于控制器休息-
@RequestMapping(value="/users/insert",method = RequestMethod.POST,headers="Accept=application/json")
public List<User> addUser(@RequestBody User user) throws ParseException {
//setter methods for setting objects and sending to backend
}
I found the issue, have set some default value to due to which this issue was coming. 我发现了这个问题,并为此设置了一些默认值。
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
Corrected it to- $http.defaults.headers.post["Content-Type"] = "application/json";
$http.defaults.headers.post["Content-Type"] = "application/json";
其更正为- $http.defaults.headers.post["Content-Type"] = "application/json";
For spring-mvc JSON-Java conversion, you need to have jackson libraries in your classpath 对于spring-mvc JSON-Java转换,您需要在类路径中包含jackson库
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.4.2</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.