Sachin Verma
Sachin Verma

Reputation: 3802

Receive params in jax-rs post method

I know ques about jaxrs params has been asked multiple times and have very good explanation of most things.But I could not find answer to a very simple question. How can i receive params in post request?

My Jax-RS method

@POST
    @Path("data")
    //@Consumes("application/json")
    @Produces("application/json")
    String getMobileServiceRepresentation(@PathParam("username") String username,@PathParam("password") String password) {
        println  username+":"+password 
        JSONObject obj=new JSONObject('{"dashboards": ["Dashbaord1","Dashboard2"]}')
        obj
    }

It prints null:null

My request is via curl ie

curl -X POST --data "username=username&password=pass" http://localhost:8080/blablaApp/api/mobileService/data

Also I have already used @Context UriInfo abc to get all context params. But no luck found

Upvotes: 0

Views: 745

Answers (1)

Xavier Coulon
Xavier Coulon

Reputation: 1600

I think you should use the @FormParam annotation instead of the @PathParam one on the method arguments. @PathParam is used when you want to retrieve parts of the request URI. In your case, you want to retrieve request body content.

Upvotes: 3

Related Questions