投稿機能を安静な Web サービスに実装しようとしています。ただし、ポスト クライアントを使用してデータをポストしようとすると、サーバーは常に 400 Bad Request Exception を返します。
以下は私のポストクライアントです:
public static HttpResponse post(String url, JSONObject data) throws IOException {
HttpClient client = new DefaultHttpClient();
StringEntity json = new StringEntity(data.toString());
json.setContentType("application/json");
HttpPost post = new HttpPost(url);
post.addHeader("Content-Type", "application/json");
post.setEntity(json);
return client.execute(post);
}
以下は、サーバー側メソッドのメソッド ヘッダーです。
@POST
@Consumes("application/json")
@Produces("text/plain")
@Path("/add")
public String addApp(@PathParam("device") String device, JSONObject json) {
プログラムを実行するたびに、post メソッドから次の HttpResponse を取得します。
HTTP/1.1 400 Bad Request [Server: nginx, Date: Mon, 30 Jul 2012 21:48:12 GMT, Content-Type: text/plain, Transfer-Encoding: chunked, Connection: keep-alive, Keep-Alive: timeout=5, X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1 Java/Sun Microsystems Inc./1.6)]
この問題の考えられる原因は何ですか?