休息客户端 java.net.ConnectException:连接超时:连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22387641/
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-08-13 15:28:00  来源:igfitidea点击:

Rest client java.net.ConnectException: Connection timed out: connect

javaspringweb-servicesrestjersey-client

提问by ramesh027

Hi i have a Spring Rest Webservice deployed in the weblogic service. I have advance rest client of google chrome which work perfectly over https I am trying to create to Client over https Client. I have ca certificate and client certificate. I created it from the below link Accessing secure restful web services using jersey clientBut i am getting exception below

嗨,我在 weblogic 服务中部署了一个 Spring Rest Webservice。我有谷歌浏览器的高级休息客户端,它可以完美地通过 https 我试图通过 https 客户端创建到客户端。我有 ca 证书和客户端证书。我从下面的链接创建它 使用球衣客户端访问安全的宁静 Web 服务但我在下面遇到异常

Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect
        at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
        at com.sun.jersey.api.client.Client.handle(Client.java:652)
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
        at com.sun.jersey.api.client.WebResource.access0(WebResource.java:74)
        at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
        at org.app.last.JerseyClient.get_JSON(JerseyClient.java:39)
        at org.app.last.JerseyClient.main(JerseyClient.java:239)
    Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:564)
        at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:395)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:530)
        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:272)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
        at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:253)
        at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:153)
        ... 6 more

回答by Angular University

Check your firewall settings to see if the outbound ports are blocked except for the browser. This happens occasionally depending on the company.

检查您的防火墙设置以查看除浏览器之外的出站端口是否被阻止。这种情况偶尔会发生,具体取决于公司。

Outbound ports are by default opened, but this might have been changed by system administrators - see this answer.

默认情况下,出站端口是打开的,但这可能已被系统管理员更改 - 请参阅此答案

Also the connection might be blocked at the level of your corporate proxy. For example in some companies you can only surf with one browser, and if you install and try to access the internet with another browser, you receive a message "It's only allowed to browser the internet with browser XX", or a timeout.

此外,连接可能在您的公司代理级别被阻止。例如,在某些公司中,您只能使用一个浏览器上网,如果您安装并尝试使用另一个浏览器访问互联网,您会收到一条消息“只能使用浏览器 XX 浏览互联网”或超时。

This works because the proxy checks for the User-Agent header.

这是有效的,因为代理会检查 User-Agent 标头。

Many proxies require authentication and only give access to authorized users. Chrome fils in your credentials automatically in some HTTP header while surfing, but your program does not do that.

许多代理需要身份验证,并且只允许授权用户访问。Chrome 浏览时会在某些 HTTP 标头中自动填写您的凭据,但您的程序不会这样做。

To troubleshoot this, try the following possibilities:

要解决此问题,请尝试以下可能性:

  • print the Url to the console with System.out.printlnand confirm that it's exactly the same as you type in Chrome

  • use a non-browser based command line utility like curl or wget to check if you can access for example google and also the endpoint

  • check your firewall settings

  • 将 URL 打印到控制台System.out.println并确认它与您在 Chrome 中键入的完全相同

  • 使用基于非浏览器的命令行实用程序(如 curl 或 wget)来检查您是否可以访问例如 google 和端点

  • 检查您的防火墙设置

回答by user3430756

It seems like you still have a problem with the proxy. and also you can have problem with the certificate

看起来你的代理仍然有问题。你也可能有证书问题

  1. check whether you're configuring the proxy properly
  2. Check whether your certificate is expired. if expired, request a new one
  3. Check with fiddler whether you're sending the certificate to server
  1. 检查您是否正确配置了代理
  2. 检查您的证书是否已过期。如果过期,请求一个新的
  3. 检查提琴手是否将证书发送到服务器