Dinesh
Dinesh

Reputation: 21

Error HTTP Status 400 - The request sent by the client was syntactically incorrect

how to send json data angular to spring controller and the return value string .can do posibile??.

HTML : last name : ng-model="user.lastname" , firstname : ng-model="user.firstname" , email : ng-model="user.email"

Angular Js :
$http({
    method  : 'POST',
    url     : baseurl+'service/user/saveangular/',
    data    : JSON.stringify($scope.user), //forms user object   
    header  : {'Content-Type' :  'application/json; charset=UTF-8'}
}).success(function(response){
        $window.alert("Success");
});

Spring :
@RequestMapping(value="saveangular",method = RequestMethod.POST)
public @ResponseBody List<User> addusersangular(@RequestBody User user) {
    System.out.println("save user angular called");
    userService.addUser(user);
    List<User> users=userService.getAllUsers();
    return users;
}

Upvotes: 0

Views: 128

Answers (1)

barkat
barkat

Reputation: 11

Please try to remove JSON.stringify() function call, because that is converting your JSON to JSON string.

$http({
    method  : 'POST',
    url     : baseurl+'service/user/saveangular/',
    data    : $scope.user, //forms user object   
    header  : {'Content-Type' :  'application/json; charset=UTF-8'}
}).success(function(response){
        $window.alert("Success");
});

Upvotes: 0

Related Questions