2013-01-04 214 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

您可以使用dig或nslookup来验证DNS服务器。您可以在您的操作系统中配置一个已知的好DNS服务器,如8.8.8.8。 异常错误消息也可能会引起误解:尝试使用wireshark捕获网络流量,然后您将看到DNS查询是否完全没有返回,“未找到”,或者DNS是否正常,但服务器主机拒绝您的请求。

您还可以通过将www.somedomain.com添加到您的主机文件及其IP地址来绕过DNS不确定性。