Here is a service that I request with a curl :

time curl -i -XPOST 'http://localhost:9080/my/service' -H "Authorization:OAuth MyToken" -H "Content-Type: application/json" -d "ids=516816b2e4b039526a235e2f,516816b2e4b039526a235e2f"

The resource :

@Path("/my")
@Consumes({"application/xml", "application/json"})
@Produces({"application/xml", "application/json", "text/json"})
@Restricted
public class MyResource {

    @POST
    @Path("/service")
    public Map<String ,Object> myService(@FormParam("ids") String myIds) {
       // service things
    }
}

That service worked fine, but it suddenly fails. Now the parameter myIds is always null, and the result of the curl is 400 bad request... I didn't change anything in this resource so it should still be working. If anybody has an idea, let me know. Thanks!

有帮助吗?

解决方案

In your curl-command, you are posting form data along with the Content-Type: application/json. Clearly this data is not valid JSON, hence the 400 bad request.

If you want to post form data, you need to use the content type application/x-www-form-urlencoded

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top