开发者

Get body content using HttpServletRequest in Jersey

开发者 https://www.devze.com 2023-03-16 19:16 出处:网络
I am using Jersey 1.7 and I am trying to access the request body in my method very similar to this question:

I am using Jersey 1.7 and I am trying to access the request body in my method very similar to this question: How do I read POST parameters for开发者_开发知识库 a RESTful service using Jersey? Body value comes in fine as email=xx@ws.com&password=test1

I tried using @Context HttpServletRequest request and tried to access the email with request.getParameter("email") but get nothing. There is nothing inside request.getparameterMap() either.

My API looks like this: @POST @Produces(...) public Response getData(@FormParam("email") String email, @FormParam("password") String password, String body, @Context HttpServletRequest request) { ....

I tried changing the position of String body and request but to no avail.

The String body gets the value perfectly fine(it is coming from an iPhone device and not through a Form Submit and so shows up in the String body). Right now, I am trying to parse the body content(email=xx@ws.com&password=test1) and get each variable like email out but that is painful.

Is there some way to get the values using request.getParameter("email") ?

Or is there any quick utility to convert the body content into String email and String password ?

TIA, Vijay


I never used form parameters myself, but the docs say it should work since forever:

@POST
@Consumes("application/x-www-form-urlencoded")
public void post(MultivaluedMap<String, String> formParams) {
    // Store the message
}

http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features

0

精彩评论

暂无评论...
验证码 换一张
取 消