How to set HttpResponse timeout for Android in Java

后端 未结 10 2189
刺人心
刺人心 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:38

    HttpParams httpParameters = new BasicHttpParams();
                HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
                HttpProtocolParams.setContentCharset(httpParameters,
                        HTTP.DEFAULT_CONTENT_CHARSET);
                HttpProtocolParams.setUseExpectContinue(httpParameters, true);
    
                // Set the timeout in milliseconds until a connection is
                // established.
                // The default value is zero, that means the timeout is not used.
                int timeoutConnection = 35 * 1000;
                HttpConnectionParams.setConnectionTimeout(httpParameters,
                        timeoutConnection);
                // Set the default socket timeout (SO_TIMEOUT)
                // in milliseconds which is the timeout for waiting for data.
                int timeoutSocket = 30 * 1000;
                HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
    

提交回复
热议问题