java.net.SocketTimeoutException: Read timed out

來源:互聯網
上載者:User


http://xye-462438944-163-com.iteye.com/blog/1205894

在調用org.apache.commons.httpclient.HttpClient類中的方法executeMethod時,如:

           Java代碼   HttpClient client = new HttpClient();       httpGet = new GetMethod(url);       client.getParams().setIntParameter("http.socket.timeout", 3000);  

HttpClient client = new HttpClient();httpGet = new GetMethod(url);client.getParams().setIntParameter("http.socket.timeout", 3000);
Java代碼   client.executeMethod(httpGet);  
client.executeMethod(httpGet);

系統可能會出現java.net.SocketTimeoutException: Read timed out  異常,而在瀏覽器中直接輸入url連結時又可以訪問,這時候可能是因為httpClient在擷取連結時候受到逾時限制。這時候只需要將逾時限制去掉即可。即將代碼client.getParams().setIntParameter("http.socket.timeout", 3000);注釋掉或者將其逾時限制時間延長


http://mywork.iteye.com/blog/430754


這兩天項目在測試環境下通過URLConnection 做資料傳遞時,出現了如下錯誤
java.net.SocketTimeoutException: Read timed out

經過尋找研究,原因是:
用戶端沒有在限定的時間內將資料發送給伺服器,伺服器為了保證服務效能,認定那個串連已經失效,所以出現上述異常。

由此得出解決方案為:
增大用戶端的逾時時間。
如 Java代碼   System.setProperty("sun.net.client.defaultConnectTimeout", String                        .valueOf(10000));// (單位:毫秒)                System.setProperty("sun.net.client.defaultReadTimeout", String                        .valueOf(10000)); // (單位:毫秒)  

System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(10000));// (單位:毫秒)System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(10000)); // (單位:毫秒)
分享到:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.