0
我開發了一個應用程序,它將使用https發佈數據到服務器。代碼在設備上運行良好,現在突然間我得到了java.net.SocketException:在少數設備中,操作超時。android https post - 例外
以下是我的代碼。
public void connectMe() {
httpClient = new DefaultHttpClient();
HttpConnectionParams
.setConnectionTimeout(httpClient.getParams(), 25000);
HttpConnectionParams.setSoTimeout(httpClient.getParams(), 25000);
try {
HttpResponse response = null;
switch (method) {
case GET:
response = httpClient.execute(new HttpGet(url));
break;
case POST:
try {
HttpPost httpPost = new HttpPost(url);
UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(
params, HTTP.UTF_8);
httpPost.setEntity(p_entity);
response = httpClient.execute(httpPost);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
以下是logcat的信息
W/System.err(3593): java.net.SocketException: The operation timed out
W/System.err(3593): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
W/System.err(3593): at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocket(OSNetworkSystem.java:130)
W/System.err(3593): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:246)
W/System.err(3593): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
W/System.err(3593): at java.net.Socket.connect(Socket.java:1074)
W/System.err(3593): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
W/System.err(3593): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:153)
W/System.err(3593): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err(3593): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err(3593): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
W/System.err(3593): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err(3593): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err(3593): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
W/System.err(3593): at com.envision.utils.MyHttpConnection.connectMe(MyHttpConnection.java:128)
我卸載並重新安裝應用程序,我以前不制定出了同樣的異常。但是在工廠數據重置之後,上面的代碼在同一個移動設備和同一個網絡中工作。
任何人都可以請解釋我發生了什麼..?我很困惑..
謝謝。
沒有沒有幫助我。我相信它不是一個臨時的網絡問題。我嘗試過不同的時間,即使我幾次重新啓動移動。僅供參考,該網址是從移動瀏覽器工作。 –