[英]AngularJS $http.post method passing null arguments to JAX-RS API
I'm trying to pass some arguments with AngularJS post method: 我正在尝试通过AngularJS post方法传递一些参数:
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 : 到我的JAX-RS方法:
@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! 我在$ http.post之前和注册方法的开始阶段都有记录器,当Web端的参数包含信息时,服务器上的每个参数都为null->我正尝试使用curl方法-一切都很好!
Anyone have an idea? 有人有主意吗?
Try to change the json object like this : 尝试像这样更改json对象:
{'email': email, 'password': password, 'phoneNumber': phoneNumber}
Javascript var ---> String name values Javascript var --->字符串名称值
JSON data is written as name/value pairs.
JSON数据被写为名称/值对。 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)
您缺少
@Consumes(MediaType.APPLICATION_JSON)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.