How to set HttpResponse timeout for Android in Java

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

    If your are using Jakarta's http client library then you can do something like:

            HttpClient client = new HttpClient();
            client.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new Long(5000));
            client.getParams().setParameter(HttpClientParams.SO_TIMEOUT, new Integer(5000));
            GetMethod method = new GetMethod("http://www.yoururl.com");
            method.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, new Integer(5000));
            method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            int statuscode = client.executeMethod(method);
    

提交回复
热议问题