How to set HttpResponse timeout for Android in Java

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

    To set settings on the client:

    AndroidHttpClient client = AndroidHttpClient.newInstance("Awesome User Agent V/1.0");
    HttpConnectionParams.setConnectionTimeout(client.getParams(), 3000);
    HttpConnectionParams.setSoTimeout(client.getParams(), 5000);
    

    I've used this successfully on JellyBean, but should also work for older platforms ....

    HTH

提交回复
热议问题