【发布时间】:2016-05-05 14:58:09
【问题描述】:
我正在尝试使用 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 方法 - 一切都很好!
有人有想法吗?
【问题讨论】:
-
cURL 默认发送 application/x-www-form-urlecoded 数据。这是您在使用@FormParam 的资源方法中所期望的那种数据。 Angular 默认发送 JSON 数据。你需要让它们匹配。如果要使用表单数据,请设置 Angular 以使用表单数据。否则设置你的资源方法接受 JSON
标签: java angularjs jersey jax-rs