Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AngularJS$http.post方法将空参数传递给JAX-RSAPI_Java_Angularjs_Jersey_Jax Rs - Fatal编程技术网

Java AngularJS$http.post方法将空参数传递给JAX-RSAPI

Java AngularJS$http.post方法将空参数传递给JAX-RSAPI,java,angularjs,jersey,jax-rs,Java,Angularjs,Jersey,Jax Rs,我试图用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'));

我试图用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'));
    }
对于我的JAX-RS方法:

@POST
@Produces(MediaType.APPLICATION_JSON )
@Path("/register")
public Response register(@FormParam("email") String email, @FormParam("password") String password,
                         @FormParam("phoneNumber") String phoneNumber) {
我在$http.post之前有日志记录程序,在register方法的基础上,当web端的参数包含信息时,服务器上的每个参数都是null->我试图使用curl方法-一切都很好


有人有主意吗?

尝试如下更改json对象:

{'email': email, 'password': password, 'phoneNumber': phoneNumber}
Javascript变量-->字符串名称值

JSON数据以名称/值对的形式写入。名称/值对由 字段名(双引号),后跟冒号,后跟 价值:


尝试如下更改json对象:

{'email': email, 'password': password, 'phoneNumber': phoneNumber}
Javascript变量-->字符串名称值

JSON数据以名称/值对的形式写入。名称/值对由 字段名(双引号),后跟冒号,后跟 价值:


我打赌这就是你的情况:

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/register")

您缺少
@Consumes(MediaType.APPLICATION\u JSON)

我打赌这就是您的情况:

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/register")

您缺少
@Consumes(MediaType.APPLICATION\u JSON)

cURL发送应用程序/x-www-form-urlecoded数据作为默认值。它是@FormParam的资源方法中所期望的数据类型。默认情况下,Angular发送JSON数据。你需要让他们匹配。如果要使用表单数据,请设置Angular以使用表单数据。否则,请将资源方法设置为默认接受JSONcURL发送应用程序/x-www-form-urlecoded数据。它是@FormParam的资源方法中所期望的数据类型。默认情况下,Angular发送JSON数据。你需要让他们匹配。如果要使用表单数据,请设置Angular以使用表单数据。否则设置你的资源方法来接受JSONU,这在我的案例中没有帮助不幸的是,在我的案例中没有帮助好,在firebug中,我试图查看构造的JSON,它看起来像{“email”:“email”:“password”:“password”,“phoneNumber”:“phoneNumber”},但是我试着用你的建议来构造JSON——这没有帮助——我得到了完全相同的响应。好吧,在firebug中,我试着看构造的JSON,它看起来像{“email”:“email”:“password”:“password”,“phoneNumber”:“phoneNumber”},但是我试着用你的建议构造JSON——这没有帮助——我得到了完全相同的响应。