2011-05-02 71 views
1

当我尝试在HttpResponse上使用BufferedReader时,我收到“SocketException:Bad file number”。 基本上我试着解析我的服务器响应。奇怪的是,它只发生在我的LG 2x(Android 2.2.2)上,我没有在Android模拟器(Google 2.2)和HTC(2.2)上看到这个错误。SocketException:错误的文件号。我该如何解决它?

In this thread someone explained why the error occurs.但是为什么这个问题只发生在LG手机上,更重要的是,我该如何解决呢?

HttpResponse response = JSONHelper.postJSONObject(WebSMSActivity.this, Consts 
               .api_url("settings"), json, 
               "Registration"); 

// Read the response for the JSON reply 
try { 
    BufferedReader in = new BufferedReader(
       new InputStreamReader(response.getEntity().getContent(), "UTF-8"), 8 * 1024); 


    // Read every line (should actually only be 
    // one 
    StringBuilder builder = new StringBuilder(); 
    for (String line = null; (line = in.readLine()) != null;) { 
     builder.append(line).append("\n"); 
     Log.w(Consts.LOG_TAG_SERVICE, line); 
    } 
    String textResponse = builder.toString(); } catch (IOException ex) {} 

回答

1

在代码中是否有这样的内容?

httpClient.getConnectionManager().shutdown(); 

就我而言,我不得不关闭我的ConnectionManager 得到响应

相关问题