Apache Http Client打印“[read] I / O error:read timed out”" [英] Apache Http Client prints "[read] I/O error: Read timed out""

查看:1808
本文介绍了Apache Http Client打印“[read] I / O error:read timed out”"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用apache http client v4.5并将其用作REST客户端。在某些情况下,我识别出一个错误[读取] I / O错误:读取超时,它来自httpclient框架,当它读取接收到的内容并将其显示为最后一条消息时。

I am using apache http client v4.5 and using it as a REST client. In some cases I recognize an error "[read] I/O error: Read timed out" which comes from the httpclient framework when it reads the received content and shows it as a last message.

似乎没有影响,但我想知道是否有人知道它的来源以及如何解决。根据以下主题(链接)似乎是mutlithreaded配置的一个问题。

It seems not to have an impact, however I wonder if somebody has an idea where it is coming from and how it can be solved. According the following thread (link) it seems to be an issue with the "mutlithreaded" configuration.

但是我只使用http客户端的默认配置,当我使用版本v4时,我不知道如何将multithreaded设置为false以查看是否没有任何区别。

However I use only the default configuration of http client and while I am using the version v4 I have no clue how I can set "multithreaded" to false to see if it makes any difference.

我也尝试设置超时但没有帮助。

I also tried to set the timeouts but it did not helped.

任何提示?

日志:

15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "HTTP/1.1 200 OK[\r][\n]"
15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Date: Tue, 29 Dec 2015 14:48:03 GMT[\r][\n]"
15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Server: Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8[\r][\n]"
15:48:05.984 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "X-Powered-By: PHP/5.6.8[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Cache-Control: nocache, private[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Content-Length: 99[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Keep-Alive: timeout=5, max=99[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Connection: Keep-Alive[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "Content-Type: application/json[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "[\r][\n]"
15:48:05.985 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "{"success":true,"data":{"id":1946,"location":"http:\/\/localhost:9001\/shop\/api\/articles\/1946"}}"
15:48:06.016 [main] DEBUG org.apache.http.wire - http-outgoing-8 << "[read] I/O error: Read timed out"

我的Http客户端初始化

my Http client initialization

HttpClientBuilder httpBuilder = HttpClientBuilder.create();

//      set timeout did not helped
//      RequestConfig.Builder requestBuilder = RequestConfig.custom();
//      requestBuilder = requestBuilder.setConnectTimeout(timeout);
//      requestBuilder = requestBuilder.setConnectionRequestTimeout(timeout);
//      requestBuilder = requestBuilder.setSocketTimeout(timeout);
//      httpBuilder.setDefaultRequestConfig(requestBuilder.build());

HttpClient httpClient = httpBuilder.build();


推荐答案

我正在使用httpclient 4.5.2和我的案例,在请求上设置超时帮助:

I'm using httpclient 4.5.2 and in my case, setting the timeouts on a request helped:

HttpPost postRequest = new HttpPost("https://...");
postRequest.setHeader(..., ...);

RequestConfig requestConfig = RequestConfig.custom()
                        .setSocketTimeout(1000)
                        .setConnectTimeout(1000)
                        .build();

postRequest.setConfig(requestConfig);

这篇关于Apache Http Client打印“[read] I / O error:read timed out”&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆