Using proxy within Java for HTTP or HTTPS connection

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

This post list all essential property names for using HTTP or HTTPS connections in Java.

These basic property names are used within Java. For HTTPS just add the S to it.

public static final String HTTP_PROXY_HOST = "http.proxyHost";
public static final String HTTP_PROXY_PORT = "http.proxyPort";
public static final String HTTP_PROXY_USER = "http.proxyUser";
public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword";

Set properties at runtime

System.getProperties().put("http.proxyHost", "ProxyURL");
System.getProperties().put("http.proxyPort", "ProxyPort");
System.getProperties().put("http.proxyUser", "UserName");
System.getProperties().put("http.proxyPassword", "Password");

Pass as program arguments

$> java -Dhttp.proxyHost=proxyhostURL -Dhttp.proxyPort=proxyPortNumber
-Dhttp.proxyUser=UserName -Dhttp.proxyPassword=Password ProxyClassHere

Remove or cleanup the proxy setting