I'm trying to pass some arguments with AngularJS post method:
function Create(email, password, phoneNumber) {
return $http.post('resources/users/register', {email: email, password: password, phoneNumber: phoneNumber}).then(handleSuccess, handleError('Error creating user'));
}
to my JAX-RS method :
@POST
@Produces(MediaType.APPLICATION_JSON )
@Path("/register")
public Response register(@FormParam("email") String email, @FormParam("password") String password,
@FormParam("phoneNumber") String phoneNumber) {
I have loggers before $http.post and on the very beggining of register method, when arguments on the web side contains info, then every argument on server is null -> I was trying to use curl method - everything was fine!
Anyone have an idea?
Try to change the json object like this :
{'email': email, 'password': password, 'phoneNumber': phoneNumber}
Javascript var ---> String name values
JSON data is written as name/value pairs. A name/value pair consists of a field name (in double quotes) , followed by a colon, followed by a value:
I bet that is your case:
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/register")
You're missing @Consumes(MediaType.APPLICATION_JSON)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.