我可以将 JSON 作为字符串发布到我的服务中,但是当我将 POST 内容更改为JSONObject
类型时会遇到问题:
服务器端代码:
@POST
@Path("/post")
@Consumes(MediaType.APPLICATION_JSON)
public Response setJson(JSONObject p){
JSONObject obj = p;
String x = obj.toString();;
System.out.println(x);
run(x);
return Response.status(201).entity(x).build();
}
卷曲命令:
curl -X POST -H "Content-Type: application/json" -d '{"follow_request_sent": false,"default_profile": false, "following": false}' http://localhost:8080/HelloWorld/webresources/helloworld/post
错误:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Unsupported Media Type)
Ps : 这种接受 JSONObject 的模式在 GET 上效果很好,但在 POST 上会产生问题