vendredi 27 février 2015

Error when calling springRest webservice by an angularJs Client

I'm trying to call a web service implementyed by Spring REST but the server respond with 400 http code bad request.I will expose some informations about that Ihope that someone can help me.


This is my controller method:



@RequestMapping(value = "/addpost", method = RequestMethod.POST, headers = "Accept=application/x-www-form-urlencoded")
public @ResponseBody
String addpost(@RequestParam PostDto post, @RequestParam UserDto user) {

postservice.addPost(post, user);
return "post inserted";

}


The manner by that I call the web service: $scope.addPost = function() {



$http({
method : 'POST',
url : 'http://localhost:8080/wall/addpost',
data : $.param({
post : $scope.postt,
user : $scope.userr
}),
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).success(function(data, status, headers, config) {
// $scope.persons.push(data);
alert("Success");
$scope.user = "";
$scope.post = "";
}).error(function(data, status, headers, config) {
alert("erreur");
// called asynchronously if an error occurs
// or server returns response with an error status.
});

};


the tow objects "userr" and "postt":



$scope.userr = {
userId : 15,
firstName : "foulen",
lastName: "ben foulen"};

$scope.postt = {
Id : "18",
datePost : "2014-12-12",
note: "Mon message"};


The response of the server:



Etat HTTP 400 - Required PostDto parameter 'post' is not present

Aucun commentaire:

Enregistrer un commentaire