2

这是我通过 curl 请求的服务:

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

资源:

@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
    }
}

该服务运行良好,但突然失败。现在参数 myIds 始终为空,并且 curl 的结果是 400 bad request...我没有更改此资源中的任何内容,因此它应该仍然可以工作。如果有人有想法,请告诉我。谢谢!

4

1 回答 1

5

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

于 2013-05-10T21:22:24.747 回答