简体   繁体   English

连接超时java HttpClient库中的异常,但不是通过Chrome浏览器?

[英]Connection timed out exception in java HttpClient library but not through chrome browser?

I have blocked a port 8070 by the following command: 我已通过以下命令阻止了端口8070:

sudo iptables -A INPUT -p tcp --destination-port 8070 -j DROP

Now, when I deploy my web application in embedded Tomcat 7 on port 8070, and If I access through the URL http://localhost:8070/app or http://192.168.1.3:8070/app , I always get the exception Connection timed out . 现在,当我将Web应用程序部署在端口7070上的嵌入式Tomcat 7中时,并且如果我通过URL http://localhost:8070/apphttp://192.168.1.3:8070/app ,我总是会收到异常Connection timed out That is usual because I have blocked that port. 这是正常的,因为我已经阻塞了该端口。

But when I access the URL http://192.168.1.3:8070/app through the chrome browser, I get the Connection Timed out error message. 但是,当我通过Chrome浏览器访问URL http://192.168.1.3:8070/app Connection Timed out出现了“ Connection Timed out错误消息。 That is also as expected. 这也符合预期。 But When I try to access http://localhost:8070/app through chrome browser, It gives me successful response. 但是,当我尝试通过chrome浏览器访问http://localhost:8070/app ,它给了我成功的响应。 This is unusual. 这很不寻常。

Why I am able to access through browser on localhost, but not through Apache HttpClient library? 为什么我可以通过本地主机上的浏览器访问,但不能通过Apache HttpClient库访问?

Note, that this should be on serverfault.com . 请注意,这应该在serverfault.com上

But you should try indicating your network interface for iptables like this: 但是您应该尝试为iptables指明网络接口,如下所示:

iptables -A INPUT -p tcp -s 192.168.1.3 --destination-port 8070 -j DROP
iptables -A INPUT -p tcp -s localhost --destination-port 8070 -j DROP

Chrome uses IPv6 so it can resolve localhost using that, the other examples are using IPv4. Chrome使用IPv6,因此可以使用IPv6解析localhost,其他示例使用IPv4。 So check your hosts file if it contains an ::1 entry for localhost? 因此,检查您的主机文件是否包含本地主机::1条目?

You can try with no IPv6 for chrome as well with this command line flag: 您也可以使用以下命令行标志尝试不为Chrome使用IPv6:

--disable-ipv6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM