How to set HttpResponse timeout for Android in Java

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

    If you're using the default http client, here's how to do it using the default http params:

    HttpClient client = new DefaultHttpClient();
    HttpParams params = client.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 3000);
    HttpConnectionParams.setSoTimeout(params, 3000);
    

    Original credit goes to http://www.jayway.com/2009/03/17/configuring-timeout-with-apache-httpclient-40/

提交回复
热议问题