公网代理配置

系统变量配置

linux 下:(profile文件增加)

1、----该配置jvm不生效

#无用户名密码
export http_proxy=http://proxy_ip:prot
export https_proxy=https://proxy_ip:prot
#有用户名密码
export http_proxy=http://username:password@proxy_ip:prot
export https_proxy=https://username:password@proxy_ip:port

2、export _JAVA_OPTIONS="-Dhttp.proxyHost=172.17.17.155 -Dhttp.proxyPort=8180 -Dhttp.nonProxyHosts=\"localhost|127.0.0.1|172.20.190.*\""(\转义符)

jvm配置(几种配置):

1、 java -Dhttp.proxyHost=172.17.17.155 -Dhttp.proxyPort=8180 Do..

2、catalina.sh  增加如下:JAVA_OPTS="-Dhttp.proxyHost=172.17.17.155 -Dhttp.proxyPort=8180 -Dhttp.nonProxyHosts=\"localhost|127.0.0.1|172.20.190.*\""

java coding

System.setProperty("http.proxyHost","172.17.17.155");
System.setProperty("http.proxyPort","8180");

URLConnection

InetSocketAddress addr = new InetSocketAddress("172.17.17.155",8180);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr); // http 代理
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();

jinfo 查看正在运行的 java 应用程序的扩展参数



猜你喜欢

转载自www.cnblogs.com/guokunv-sj/p/12098911.html