HTTPURLConnection 是否通过 SSH 隧道?
Does HTTPURLConnection go through SSH tunnel?
我有一个程序需要访问google api,但由于我在中国,所以我必须使用ssh/vpn。我用yingwa客户端打开ssh,在浏览器中可以访问api。但是当我 运行 我的 java 代码时,它抛出一个 exception:network is unreachable。
任何人都可以帮助我吗?
ps: 我没有为httpurlconnection设置代理
您必须在 java 中将 SOCKS 代理设置为您的 ssh 隧道和端口。
在此处查看第 2.4 章:http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
There are 2 system properties related to SOCKS:
socksProxyHost
for the host name of the SOCKS proxy server
socksProxyPort
for the port number, the default value being 1080
我有一个程序需要访问google api,但由于我在中国,所以我必须使用ssh/vpn。我用yingwa客户端打开ssh,在浏览器中可以访问api。但是当我 运行 我的 java 代码时,它抛出一个 exception:network is unreachable。 任何人都可以帮助我吗?
ps: 我没有为httpurlconnection设置代理
您必须在 java 中将 SOCKS 代理设置为您的 ssh 隧道和端口。
在此处查看第 2.4 章:http://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html
There are 2 system properties related to SOCKS:
socksProxyHost
for the host name of the SOCKS proxy server
socksProxyPort
for the port number, the default value being 1080