java 如何解决对另一台服务器的 Http 请求中的 org.apache.http.conn.ConnectTimeoutException?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31914481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 19:21:18  来源:igfitidea点击:

How to resolve org.apache.http.conn.ConnectTimeoutException in Http Request to another server?

java

提问by Greesh Kumar

I am using HttpClient to handling http requests and when I try to contect with my target server I am getting a error as

我正在使用 HttpClient 来处理 http 请求,当我尝试与目标服务器联系时,我收到错误消息

org.apache.http.conn.ConnectTimeoutException: Connect to prdalonegk.alonegk.com:9090 timed out

where prdalonegk.alonegk.com:9090is my xmpp server

prdalonegk.alonegk.com:9090我的 xmpp 服务器在哪里

采纳答案by A4L

Make sure the host prdalonegk.alonegk.comis reacheable

确保主机prdalonegk.alonegk.com可达

ping prdalonegk.alonegk.com

and that it is can accept connections on port 9090(firewall).

并且它可以接受端口9090(防火墙)上的连接。

If all is ok, then try to increase the connection timeout:

如果一切正常,则尝试增加连接超时:

RequestConfig.Builder requestBuilder = RequestConfig.custom();
requestBuilder = requestBuilder.setConnectTimeout(3000L); /* in ms */

Please refere to the request builder javadocsfor all the settings you may provide.

有关您可能提供的所有设置,请参阅请求构建器 javadocs