0

The below lines of code

HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
HttpResponse response2 = httpexecutor.execute(request2, conn, context);
log.info("Status Line "+response2.getStatusLine());

while executing the second statement my request/response is blocked by proxy. How to debug this.? While the same statement executing from my local environment where no proxy is configured, am able to see the log returns the below code "Status Line HTTP/1.1 200 OK"

4

1 回答 1

0

我认为您正在寻找的是在请求上设置超时 - 基本上告诉执行者在一定时间内无法建立连接时放弃。

这篇 SO 文章涵盖了这一点:Java HTTP Client Request with defined timeout

接受的答案包含关于 Apache 的实现有两个超时这一事实的重要信息 - 请务必阅读。

请注意,您实际上无法区分由其他问题引起的连接失败——您所知道的只是您的尝试超时。在您对用户的回复中,您可能会说“无法连接到主机 XXXXX。可能的原因是您的 Internet 连接已关闭,或者您的代理服务器阻止了与该主机的出站连接。”

于 2013-09-01T18:16:31.547 回答