本文介绍了如果请求超时,HttpClient将多次执行请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HttpClient 超时,则会执行4次请求.如果它没有超时,则说明工作正常.它与 HttpClient 有关吗?

HttpClient executes request 4 times if it times out. If it does not time out then it is working fine. Is it related to HttpClient?

推荐答案

我发现,如果请求失败,则执行4次请求是 HttpClient 的默认行为.我不确定其他类型的失败,但至少可以超时.

I found that it is HttpClient's default behaviour to execute requests 4 times if it fails. I am not sure about other kind of failures but at least with time out.

要禁用此行为,请执行以下操作:

To disable this behaviour do this :

DefaultHttpClient client = new DefaultHttpClient();
// Disable default behavior of HttpClient of retrying requests in case of failure
((AbstractHttpClient) client).setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));

此处重试计数设置为 0 以禁用重试.

Here retry count is set to 0 to disable retry.

我从此内容找到了解决方案博客.

这篇关于如果请求超时,HttpClient将多次执行请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 11:35
查看更多