java - Apache Httpcomponent Fluent API 在一些 IO 错误后挂起

标签 java apache-httpclient-4.x fluent

我正在使用 Apache Http Fluent API 4.3.2 定期向不太可靠的 API 发出 HTTPS 请求。我的代码如下所示:

try {
    Request get = Request.Get(url);
    get.connectTimeout(10000);
    get.socketTimeout(10000);
    Executor executor = Executor
        .newInstance(HttpClientBuilder.create().build());
    String response = executor.execute(get).returnContent().asString();
} catch (Exception e) {
    LOG.error("Http get threw an exception", e);
}

它可以工作几天然后扔掉

javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

execute 方法数百次。

在一些异常方法 execute 之后永远阻塞。 我可以建议执行程序用尽连接,但不知道如何处理。

一个月没有回音?我准备好接受“没有解决方案”这样的答案。

最佳答案

我遇到了同样的问题,在出现一些 404 错误后 Fluent 挂起。

我通过中止请求修复了它。

req.abort(); 

http://hc.apache.org/httpcomponents-client-ga/fluent-hc/apidocs/org/apache/http/client/fluent/Request.html#abort()

关于java - Apache Httpcomponent Fluent API 在一些 IO 错误后挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31857343/

相关文章:

java - 在没有锁定的情况下从多个线程写入同一个文件,Java

java - 使用 HttpResponseInterceptor 来操作响应

c# - 类方法返回 `this`是不好的做法吗?

c# - 是否有一种流畅的方法来处理 WinForm 事件?

java - 当 subview 可用时从父 fragment 调用子 fragment 方法?

java - 此代码示例中的关键字 this 引用什么?

java - 未生成 EMMA coverage.ec

java - Elasticsearch错误: MapperParsingException: failed to parse

java - 使用流畅的接口(interface)重构长方法

java - 获取带有列名的 Hibernate 实体字段