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/json")
public @ResponseBody
String addpost(@RequestBody PostDto post, @RequestBody UserDto user) {
postservice.addPost(post, user);
return "post inserted";
}
The manner by that I call the web service: $scope.addPost = function() {
$scope.addPost = function() {
$http({
method : 'POST',
url : 'http://localhost:8080/wall/addpost',
data : ({
post : $scope.postt,
user : $scope.userr
}),
}).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 : null,
note: "Mon message"};
The response of the server:
Etat HTTP 400 - Required PostDto parameter 'post' is not present
these are the headers of request and reponse:
Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/wall/addpost
Request Method:POST
Status Code:400 Mauvaise Requête
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:125
Content-Type:application/json;charset=UTF-8
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/wall/view/test.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Request Payloadview source
{post: {idpost: 18, datePost: null, note: "Mon message"},…}
post: {idpost: 18, datePost: null, note: "Mon message"}
datePost: null
idpost: 18
note: "Mon message"
user: {userId: 15, firstName: "foulen", lastName: "ben foulen"}
firstName: "foulen"
lastName: "ben foulen"
userId: 15
Response Headersview source
Connection:close
Content-Length:983
Content-Type:text/html;charset=utf-8
Date:Fri, 27 Feb 2015 11:16:49 GMT
Server:Apache-Coyote/1.1