Aniru Aniru - 1 month ago 33
reST (reStructuredText) Question

How to POST with 2 parameters using curl? REST. Java

I want introduce two String params (type and content) in the method "createPost".

I am using this line:

curl -i -u pepe:pepe -d 'type=Link&content=www' --header "Content-Type: application/json" http://localhost:8080/web-0.0.1-SNAPSHOT/api/user/post

But... that line introduces "type=Link&content=www" in the first parameter and leaves the second empty.

The method is this:

public Response createPost(@FormParam("type") String type, @FormParam("content") String content) {
postEJB.createPostUserRest(type, content);
URI userURI = uriInfo.getAbsolutePathBuilder().build();
return Response.created(userURI).build();

How could I enter "Link" in the first and "www" in the second?

Many thanks to all and sorry for my poor English.


First of all, as createPost is annotated with @POST, you should probably pass -X POST to curl.

Also, the method expects MediaType.APPLICATION_JSON, and although you set Content-Type: application/json header with curl, that's not really compatible with the -d option like that. The value of the -d option in this case should be a JSON string, like this:

curl -X POST -i -u pepe:pepe -d '{"type":"Link","content":"www"}' ...