2013-04-01 95 views
0

嗨我沒有得到迴應Android 2.2版本,但完美的工作4.0 versionHTTP post在json Android2.2版本中沒有得到響應?

我的代碼如下:

HttpPost method = new HttpPost(url); 
     UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(nameValuePairs); 
     System.out.println("**************Request=>"+urlEncodedFormEntity.toString()); 
     method.setEntity(urlEncodedFormEntity); 
     HttpResponse response = executeMethod(method); 

     HttpEntity entity = response.getEntity(); 
     if(entity!=null) { 
      String value = EntityUtils.toString(entity); 
      Log.i("", "Meesage"+value); 

     } 
     String responseStr = EntityUtils.toString(response.getEntity()) 

在運行2.2版本,我得到這個類型的日誌貓的消息

04-01 11:41:12.101: W/KeyCharacterMap(13719): Can't open keycharmap file 
04-01 11:41:12.101: W/KeyCharacterMap(13719): Error loading keycharmap file '/system/usr/keychars/sec_touchscreen_.kcm.bin'. hw.keyboards.65538.devname='sec_touchscreen ' 
04-01 11:41:12.101: W/KeyCharacterMap(13719): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 

請給我的解決方案?

+0

PLZ後相關logcat的結果,並確保您使用的後臺線程製作httpprequest從主UI線程 –

+0

該錯誤無關,與HTTP請求。問題是在別處 –

+0

你有任何答覆或不?你調試你的代碼? –

回答

0

試試像這樣。

try { 

     HttpClient client = new DefaultHttpClient(); 
     HttpConnectionParams.setConnectionTimeout(client.getParams(), 20000); 
     HttpConnectionParams.setSoTimeout(client.getParams(), 2000); 

     HttpResponse response; 
     HttpPost post = new HttpPost("Your url"); 


     response = client.execute(post); 

     InputStream in = response.getEntity().getContent(); 
     String a = convertStreamToString(in); 
     //Log.v("Response", ""+a); 

      } catch (Exception e) { 
      e.printStackTrace(); 
     } 


//Json response 
private String convertStreamToString(InputStream is) { 
      // TODO Auto-generated method stub 
      BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 
      StringBuilder sb = new StringBuilder(); 

      String line = null; 

       try { 
        while ((line = reader.readLine()) != null) { 

         sb.append(line + "\n"); 
        } 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } finally { 
        try { 
         is.close(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
       } 
       return sb.toString(); 
    } 
+0

HttpClient client = new DefaultHttpClient(); \t \t response = client.execute(method); – Gomathi

+0

這不起作用 – Gomathi

+0

@Gomathi您是否爲Android 4.0版本提供了嚴格模式線程策略? – Yugesh