2015-02-03 2 views
0

다음 코드를 실행하면 대부분의 경우 "피어에 의한 연결 재설정"예외가 발생합니다.대부분의 경우 내 안드로이드 응용 프로그램에서 피어 예외로 연결 재설정을받습니다.

 String rest = System.setProperty("http.keepAlive", "false"); 
     String uri = WEB_LOG_IN + "?user_username=" + user_email 
       + "&user_password=" + user_pass + "&user_mac=" + user_mac; 
     HttpClient client = new DefaultHttpClient(); 

     HttpPost httppost = new HttpPost(uri); 
     HttpResponse response; 

     String s; 
     try { 
      response = client.execute(httppost); 
      s = new String(EntityUtils.toByteArray(response.getEntity()), 
        "UTF-8"); 

      // read json 

      if (s.length() > 2) 
       return readlogin_info(s); 
      else 
       return false; 

     } catch (ClientProtocolException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      return false; 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      return false; 

     } 

String rest = System.setProperty("http.keepAlive", "false"); 반환에는 "http.keepAlive"속성을 의미하는 null로.

httpurlconnection을 사용해 보았지만 작동하지 않았습니다.

코드가 일부 ISP에서는 문제없이 작동한다고 생각하기 때문에 혼란 스럽습니다.

+0

내 조사! String pro = System.getProperty ("http.keepAlive"); \t String rest = System.setProperty ("http.keepAlive", "false"); 은 장치가 (Mikrotik RB951Ui 라우터)를 통해 인터넷에 연결될 때 null을 반환하는 경우가 있습니다. –

답변

0

내 조사를 기반으로 Mikrotik 라우터 지연으로 인한 예외가 발생했습니다! (어쩌면 내가 잘못했는지 정정하십시오!) 그래서 서버에서 응답을받을 때까지 실행 섹션을 넣으십시오. 여러 번 실행 한 후에 성공적으로 연결하려고 시도한 후 2 회가 지나면 볼 수 있습니다.

int count = 0; 
while (s == null) { 
      count++; 
      try { 
       response = client.execute(httpGet); 
       s = new String(
         EntityUtils.toByteArray(response.getEntity()), 
         "UTF-8"); 
       // read json 
       if (s.length() > 2) 
       { 
        return readlogin_info(s); 
       } 
       else 
       { 
        return false; 
       } 

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

      }