2011-05-26 32 views
7

Android emülatöründen, huzurlu bir sunucuya istek göndermeye çalışıyorum.desteklenmeyen ortam türü

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

sunucusunun kod:

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

Ha, bu sooo tam olarak bakıyordu sorundur! Çok teşekkürler – woezelmann

cevap

7

sorun sunucu bilmiyor ki müşterinin

415 Unsupported Media Type.

kodu: Ama her zaman hata olsun İstemcinin talebinin medya türü. istemci kodunda böyle bir şey deneyin :

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

İlgili konular