7
我嘗試從android模擬器發送請求到寧靜的服務器。但是,我總是得到錯誤:不支持的Android休息客戶端的媒體類型
415 Unsupported Media Type.
客戶端的代碼:
public JSONtest() throws Exception, IOException{
HttpPost request = new HttpPost(AppServerIP);
JSONObject param = new JSONObject();
param.put("name", "weiping");
param.put("password", "123456");
StringEntity se = new StringEntity(param.toString());
request.setEntity(se);
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
String retSrc = EntityUtils.toString(httpResponse.getEntity());
System.out.println(httpResponse.getStatusLine().getReasonPhrase());
}
服務器的代碼:
public class resource {
@POST
@Path("/trigger")
@Consumes(MediaType.APPLICATION_JSON)
public Response trigger(JSONObject notify) throws Exception{
return Response.status(Response.Status.OK).entity("134124").tag("213q").type(MediaType.APPLICATION_JSON).build();
}
哈,這是SOOO正是我所面臨的問題!非常感謝 – woezelmann 2012-08-10 07:49:57