如果请求超时,HttpClient将多次执行请求

编程入门 行业动态 更新时间:2024-10-22 23:23:47
本文介绍了如果请求超时,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将多次执行请求

本文发布于:2023-11-08 13:45:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569538.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HttpClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!