java 无法通过代理建立隧道。代理返回 HTTP/1.1 503 服务不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42904148/
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
Unable to tunnel through proxy. Proxy returns HTTP/1.1 503 Service Unavailable
提问by ManKeer
I want to connect to an intranet server, the url that I need to connect is:
我想连接内网服务器,需要连接的url是:
URLConnection conn = new URL("https://mywebsite").openConnection();
When I reach to the connect method call through:`
当我通过以下方式调用连接方法时:`
conn.connect();
I'm getting the following exception:
我收到以下异常:
java.io.IOException: Unable to tunnel through proxy. Proxy rerurns HTTP/1.1 503 Service Unavailable"
at sun.net.www.protocol.httpHttpURLConnection.doTunneling
How can I solve this exception, I have tried many solutions published on the net, but without any luck.
我该如何解决这个异常,我已经尝试了网上发布的许多解决方案,但没有任何运气。
回答by Jakub Holy
What helped to me was to unset all proxy properties in the environment (http_proxy
etc env variables; java properties such as -Dhttp.proxyHost=..
had, surprisingly, no effect). My URL (https://mycompany.example.com/service) was accessible directly (because it was on the internal network) but not through the proxy.
对我有帮助的是取消设置环境中的所有代理属性(http_proxy
等环境变量;诸如-Dhttp.proxyHost=..
had 之类的java 属性,令人惊讶的是,没有效果)。我的 URL ( https://mycompany.example.com/service) 可以直接访问(因为它在内部网络上),但不能通过代理访问。
So check where the service lives and check for proxy-related environment variables.
因此,请检查服务所在的位置并检查与代理相关的环境变量。
回答by Guillermo
I hade a similar case. I'm using the maven jaxws-maven-plugin
plugin and trying to generate java code from a WSDL laying on another server.
The problem was that the plugin is picking up the environment variable httpproxy
, but not the noproxy
variable. I solved that by adding it manually as a JVM argument:
我也遇到过类似的情况。我正在使用 mavenjaxws-maven-plugin
插件并尝试从位于另一台服务器上的 WSDL 生成 java 代码。问题是插件正在获取环境变量httpproxy
,而不是noproxy
变量。我通过手动添加它作为 JVM 参数解决了这个问题:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>wsdltoJava</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>https://someService.yourcompany.net/Service/Service?wsdl</wsdlUrl>
</wsdlUrls>
<vmArgs>
<vmArg>-Dhttp.nonProxyHosts=*.yourcompany.net</vmArg>
</vmArgs>
<keep>true</keep>
<packageName>com.yourcompany.package</packageName>
<sourceDestDir>your/target/directory</sourceDestDir>
</configuration>
</execution>
</executions>