0

I want to connect to an https:// URL in Java that requires proxy.

I have 2 proxies in the system:

HTTP  -> proxy.teatre.guerrilla:8080
HTTPS -> proxy.teatre.guerrilla:8443

I've tried with

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.teatre.guerrilla", 8080));

URL url = new URL ( urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);

But I got a Exception in thread "main" java.net.ConnectException: Connection timed out: connect

and I haven't seen the type Proxy.Type.HTTPS

I also tried

System.setProperty("http.proxyHost", "proxy.teatre.guerrilla");
System.setProperty("http.proxyPort", "8080");

System.setProperty("https.proxyHost", "proxy.teatre.guerrilla");
System.setProperty("https.proxyPort", "8443");

with the same result.

I also tried to add this as Program arguments and VM arguments....

-Dhttp.proxyHost=proxy.teatre.guerrilla -Dhttp.proxyPort=8800 -Dhttps.proxyHost=proxy.teatre.guerrilla -Dhttps.proxyPort=8443
carles xuriguera
  • 930
  • 1
  • 14
  • 30

2 Answers2

0

You better not include proxy handling in your code. You never know in which environment your JAVA application will be running. So please configure the PROXY settings with JVM args like that: How do I set the proxy to be used by the JVM

Mick
  • 954
  • 7
  • 17
0

please try

System.setProperty("http.proxyHost", "proxy.teatre.guerrilla");
System.setProperty("http.proxyPort", 8080);
Nuñito Calzada
  • 4,394
  • 47
  • 174
  • 301