使用 Apache HttpClient,为什么我的连接超时不起作用?

发布于 2024-07-05 07:40:43 字数 205 浏览 4 评论 0原文

我的 httpclient 实现在调用 doGetConnection() 时偶尔会引发异常。 但是,我设置了以下超时,

_moHttpClient.setHttpConnectionFactoryTimeout(30000);

看起来几乎就像我的超时没有被接收。 是否还有其他地方需要设置超时以确保这种行为不会再次发生

My implementation of httpclient occasionally throws an exception when calling doGetConnection(). However, I have the following timeout set

_moHttpClient.setHttpConnectionFactoryTimeout(30000);

it looks almost like my timeout is not being picked up. Is there anywhere else I need to set a timeout to ensure this behaviour does not re-occur

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

惯饮孤独 2024-07-12 07:40:43

你抛出了什么异常?

不要忘记您有两个超时需要更改/检查。 从 HttpConnectionParams 中

setConnectionTimeout()
setSoTimeout()

,您可以控制等待连接到服务器的时间,以及套接字上的操作在超时之前需要多长时间。

What exception are you getting thrown ?

Don't forget you have two timeouts to change/check. From HttpConnectionParams

setConnectionTimeout()
setSoTimeout()

so you can control how long you wait for a connection to the server, and how long operations on the socket can take before timing out.

神回复 2024-07-12 07:40:43
    HttpConnectionManagerParams cmparams = new HttpConnectionManagerParams();
    cmparams.setSoTimeout(10000);
    cmparams.setTcpNoDelay(true);
    HttpConnectionManager manager = new SimpleHttpConnectionManager();
    manager.setParams(cmparams);
    params = new HttpClientParams();
    params.setSoTimeout(5000);
    client = new HttpClient(params, manager);

我想知道为什么我设置了两个不同的 SoTimeouts。 也许我想找出哪一个实际上是活跃的,因为我在使用它时遇到了和你一样的问题。

上面的内容现在是我们这里的实时代码,但我不能说它是否有效,因为它是正确的,或者因为上帝正在对我微笑(而另一端通常总是可用的)。

    HttpConnectionManagerParams cmparams = new HttpConnectionManagerParams();
    cmparams.setSoTimeout(10000);
    cmparams.setTcpNoDelay(true);
    HttpConnectionManager manager = new SimpleHttpConnectionManager();
    manager.setParams(cmparams);
    params = new HttpClientParams();
    params.setSoTimeout(5000);
    client = new HttpClient(params, manager);

I wonder why I have two different SoTimeouts set. Maybe I was trying to find out which one was actually active, as I had the same problems as you when I used it.

The above is in live code at our place right now, but I cannot say whether it works because it's correct, or because providence is smiling down on me (and the other end is usually always available).

总以为 2024-07-12 07:40:43

cmparams.setSoTimeout(10000);

默认情况下,此选项适用于所有 HttpClient。

params.setSoTimeout(5000);

这是针对特定 httpclient 的。

cmparams.setSoTimeout(10000);

This one is for all HttpClient by default.

params.setSoTimeout(5000);

And this one is for a particular httpclient.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文