Alex
Alex

Reputation: 34978

How can I fetch data from an HTTPS Url via Proxy?

I am getting Connection timed out: connect.

My code:

    System.setProperty("http.proxyHost", "proxy.mycompany.com");
    System.setProperty("http.proxyPort", "8080");

    String url = URL_BASE + "&limit=5";
    URL u = new URL(url);
    BufferedReader in = new BufferedReader(
            new InputStreamReader(
            u.openStream()));

    String inputLine;

    while ((inputLine = in.readLine()) != null)
        System.out.println(inputLine);

    in.close();

Upvotes: 0

Views: 1414

Answers (2)

Sylar
Sylar

Reputation: 2333

I suggest you fetch the content using apache http commons httpclient. There you can set proxy authentication on the client without the need to modify the global jvm properties.

Upvotes: 1

MarcoS
MarcoS

Reputation: 13564

If you're fetching a URL on HTTPS, then you must set https.proxyHost and https.proxyPort. See documentation on Java Networking and Proxies, section 2.2.

System.setProperty("https.proxyHost", "proxy.mycompany.com");
System.setProperty("https.proxyPort", "8080");

assuming that proxy.mycompany.com on port 8080 is also an HTTPS proxy

Upvotes: 4

Related Questions