宿主机开了 vpn ,可以访问 google
测试类
import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class Test { public static void main(String[] args) throws IOException { URL url = new URL("https://www.google.com"); URLConnection cOnnection= url.openConnection(); connection.connect(); InputStream inputStream = connection.getInputStream(); byte[] bytes = new byte[1024]; while (inputStream.read(bytes) >= 0) { System.out.println(new String(bytes)); } } } 编译后执行
java Test 结果是能正常访问到 google ,但是在 shell 中 ping google 是没法通的
明明查资料,要给程序设置代理才能访问 google ,也就是下面这样才能访问到
java -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=7890 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=7890 Test java 程序是默认就会走本机的代理吗,不需要额外设置?
