我有一个简单的Android客户端,代码如下:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://192.168.0.11:8080/MyWeb/Test/tests/save");
httpPost.addHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json");
httpPost.setEntity(new StringEntity(new Gson().toJson(new Hank()), HTTP.UTF_8));
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseBody = EntityUtils.toString(entity);
System.out.println(responseBody);
目标是从服务器上的JAX-RS资源触发响应。这是服务器代码:
@Path("/save")
@POST
@Produces("application/json")
@Consumes("application/json")
public Hank saveHank(Hank hank) throws JSONException {
System.out.println(hank);
return hank;
}
responseBody是一个HTML页面,其中包含资源不可用的信息。有什么问题?