json - Spring MVC + AngularJS 415 Unsupported Media Type -
the question simple , know answered in many other question none worked me. using spring mvc , angularjs getting angularjs 415 unsupported media type !
i tried setting angular header application/json
tried @consumes
annotation on server side
tried consumes ="application/json"
tired consumes ="application/application/json;charset=utf-8'
tried consumes ={"application/json","application/xml"}
tried setup produces property.
i tried explicitly setting hear content type on client match 1 on server but, nothing worked ! here related questions none helped ! 1
2 3
here controller
/** * created adelin.ghanayem@gmail.com */ @controller @requestmapping(value = "/administration/places") public class placescontroller { private placesservice service; @autowired public placescontroller(placesservice service) { this.service = service; } @requestmapping(method = requestmethod.post,consumes = {"application/json;charset=utf-8"}) public string newplace(@requestbody place places) { string id = service.addnewplace(places); return "/administration/places/" + id; } @requestmapping(value = "/{id}") public place getbyid(@pathvariable string id) { return new place(); } }
and angularjs controller
function newplacescontroller(scope, http) { scope.place = {}; scope.add = function () { http.post(urls.addnewplace, scope.place,{'content-type': 'application/json'}).success(function (value) { console.log("got !"); }).error(function (value) { console.log("cur!"); }); } } newplacescontroller['$inject'] = ['$scope', '$http'];
try it:
@requestmapping(method = requestmethod.post,consumes = {"application/json;charset=utf-8"}, produces={"application/json;charset=utf-8"}) public string newplace(@requestbody place places) { string id = service.addnewplace(places); return "/administration/places/" + id; }
and make sure included jackson databind library.
Comments
Post a Comment