You can do it in two ways:
Via Command Line as JVM arguments:
java -Dhttp.proxyHost=proxyServerIPorHostName -Dhttp.proxyPort=proxyServerPort -Dhttp.proxyUser=userName -Dhttp.proxyPassword=password HelloWorldProgramAs System properties in Java program:
System.getProperties().put("http.proxyHost",
"proxyServerIPorHostName");
System.getProperties().put("http.proxyPort",
"proxyServerPort");
final String authUser = "user";
final String authPassword = "password";
Authenticator.setDefault(
new Authenticator()
{
public
PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
authUser, authPassword.toCharArray());
}
}
);
System.setProperty("http.proxyUser",
authUser);
System.setProperty("http.proxyPassword", authPassword);
set the above properties in your java code before accessing any network resources outside your corporate intranet.
No comments:
Post a Comment