How to set HttpResponse timeout for Android in Java

后端 未结 10 2229
刺人心
刺人心 2020-11-22 08:02

I have created the following function for checking the connection status:

private void checkConnectionStatus() {
    HttpClient httpClient = new DefaultHttpC         


        
10条回答
  •  暖寄归人
    2020-11-22 08:16

    If you are using the HttpURLConnection, call setConnectTimeout() as described here:

    URL url = new URL(myurl);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(CONNECT_TIMEOUT);
    

提交回复
热议问题