简体   繁体   English

Java设置简单代理

[英]Java Setting up a Simple Proxy

I use a vpn so I need a proxy to make a REST post on POSTMAN. 我使用的是VPN,因此我需要一个代理才能在POSTMAN上发布REST帖子。 So I setup a Proxy IP and port and it works... 所以我设置了代理IP和端口,它可以工作...

But in Java I get connection timeout even tho I setup the proxy programally. 但是在Java中,即使通过程序设置代理,我也会获得连接超时。

System.setProperty("http.proxyHost",ip);
System.setProperty("http.proxyPort",port);

What's the reason for this? 这是什么原因?

Java has different properties for http and https proxy settings, since you might want to use a different proxy for each. Java对于http和https代理设置具有不同的属性,因为您可能希望为每个代理使用不同的代理。

In this case you need to set https.proxyHost and https.proxyPort . 在这种情况下,您需要设置https.proxyHosthttps.proxyPort

Full details of the Networking Properties Java supports are listed here: 此处列出了Java支持的网络属性的完整详细信息:

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/doc-files/net-properties.html https://docs.oracle.com/zh_cn/java/javase/11/docs/api/java.base/java/net/doc-files/net-properties.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM