Unsupported media type for Android client client

I am trying to send a request from an android emulator to a quiet server. But I always get the error message:

415 Unsupported media type.

Client code:

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()); } 

Server Code:

 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(); } 
+7
source share
1 answer

The problem is that the server does not know the media type of the client request. Try something similar in client code:

request.setHeader("Content-Type", "application/json");

+7
source

All Articles