2013-01-04 3 views
0

HTTP 연결을 사용 중이며 내 앱이 주기적으로 서버에 연결합니다. 특정 시점 이후에 서버에 연결할 수없고 모든 연결에 대해 예외가 발생합니다.서버에서 연결을 거부했습니다.

java.net.ConnectException; www.somedomain.com/xxx.xxx.xxx.x에 연결하지 못했습니다. (포트 80) : 실패 연결 : ENETUNREACH을 (네트워크에 연결할 수)

org.apache.http.conn.HttpHostConnectException, http://www.somedomain.com에 연결이

java.net.UnknownHostException 거부, 호스트를 확인할 수 없습니다 "를 www.somedomain .com ": 호스트 이름과 연결된 주소가 없습니다.

서버가 차단 될 수 있습니다. 어떤 지점. 왜 이런 일이 일어날 지 모릅니다. 앱을 다시 설치하면 연결이 여전히 차단됩니다.

편집 : 여기에 HTTP를 보내기위한 코드가

public String send() throws ClientProtocolException, IOException { 
    InputStream is = null; 
    DefaultHttpClient httpclient = null; 
    HttpResponse response = null; 
    try { 
     System.setProperty("http.keepAlive", "false"); 
     httpclient = new DefaultHttpClient(); 
     HttpProtocolParams.setUseExpectContinue(httpclient.getParams(), false); 
     HttpRequestRetryHandler retryHandler = new HttpRequestRetryHandler() { 

      public boolean retryRequest(IOException exception, int executionCount, 
        HttpContext context) { 
       // retry a max of 5 times 
       if(executionCount >= 5){ 
        return false; 
       } 
       if(exception instanceof NoHttpResponseException){ 
        return true; 
       } else if (exception instanceof ClientProtocolException){ 
        return true; 
       } 
       return false; 
      } 
     }; 
     httpclient.setHttpRequestRetryHandler(retryHandler); 
     String proxyHost = android.net.Proxy.getDefaultHost(); 
     int proxyPort = android.net.Proxy.getDefaultPort(); 
     // Set Proxy params of client, if they are not the standard 
     if (proxyHost != null && proxyPort > 0) { 
      HttpHost proxy = new HttpHost(proxyHost, proxyPort); 
      httpclient.getParams().setParameter(
        ConnRoutePNames.DEFAULT_PROXY, proxy); 
     } 
     HttpPost httppost = new HttpPost(url); 
     httppost.setEntity(new UrlEncodedFormEntity(qData)); 
     response = httpclient.execute(httppost); 
     is = response.getEntity().getContent(); 
     return inputStreamToString(is); 
    } finally { 
     try { 
      if (is != null) { 
       is.close(); 
      } 
     } catch (Throwable e) { 
     } 
     try { 
      if (response != null && response.getEntity() != null) { 
       response.getEntity().consumeContent(); 
      } 
     } catch (Throwable e) { 
     } 
     try { 
      if (httpclient != null 
        && httpclient.getConnectionManager() != null) { 
       httpclient.getConnectionManager().shutdown(); 
      } 
     } catch (Throwable e) { 
     } 
    } 
} 
+0

은 코드를 제공합니다. 당신도 서버 - 애플 리케이션을 개발합니까? – sschrass

+0

@SatelliteSD 게시판을 업데이트했습니다. –

+0

"호스트를 확인할 수 없습니다"www.somedomain.com ": 호스트 이름과 연결된 주소가 없습니다. DNS 문제와 유사합니다. – kabuko

답변

1

당신은 DNS 서버를 확인하기 위해 발굴 또는 nslookup을 사용할 수 있습니다 요청합니다. 당신은 8.8.8.8과 같이 당신의 OS에서 잘 알려진 좋은 DNS 서버를 구성 할 수 있습니다. 예외 오류 메시지는 오해의 소지가 있습니다. wireshark를 사용하여 네트워크 트래픽을 캡처 한 다음 DNS 쿼리가 아무것도 반환하지 않거나 "찾을 수 없음"또는 DNS가 정상인지 여부를 확인하지만 요청을 거부하는 서버 호스트 .

또한 IP 주소가있는 호스트 파일에 www.somedomain.com을 추가하여 DNS 불확실성을 우회 할 수 있습니다.

관련 문제