我正在使用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) {
}
}
}
提供您的代码。你也开发服务器应用程序吗? – sschrass
@SatelliteSD我更新了帖子 –
“无法解析主机”www.somedomain.com“:没有与主机名关联的地址”听起来更像是一个DNS问题。 – kabuko