我正在使用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