I am trying to post query parameters from angular JS to rest server. But the value received in the rest is always null. Can anyone please tell what i am missing?
Angular code,
$http({
method : 'POST',
url : '/rest/user/changePassword',
data : {'id':$scope.user.id, 'password':$scope.user.password, 'newpassword':$scope.user.newpassword},
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data){
console.log(' data ');
});
Rest code,
@Path("/changePassword")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response changePassword(@QueryParam("id") int id,
@QueryParam("password") String password,
@QueryParam("newpassword") String newpassword, @Context UriInfo request) {
System.out.println(" id " + id + " re " + request.getQueryParameters().getFirst("id"));
System.out.println(" password " + password + " "+ request.getQueryParameters().getFirst("password"));
System.out.println(" newpassword " + newpassword + " " + request.getQueryParameters().getFirst("newpassword") );
return new Response('asd');
}
I tried $.param in angular side, tried to get parameters from HttpServletRequest but the result is always null.