HTTP Proxy Settings in JAVA (Eclipse)

625 views
Skip to first unread message

Prateek Chandra Jha

unread,
Jul 12, 2012, 6:22:19 PM7/12/12
to wncc...@googlegroups.com

I was trying to implement proxy authentication in JAVA in eclipse using the code below. But it isn't working.

Infact when I run this code with the HttpUrlConnection, It does not render the website's HTML code but displays the code itself.

What is missing ?

For authentication, I used java.net.Authenticator to set proxy's configuration and set the system properties http.proxyUser and http.proxyPassword.

final String authUser = "myuser";
final String authPassword = "secret";

System.setProperty("http.proxyHost", "hostAddress");
System.setProperty("http.proxyPort", "portNumber");
System.setProperty("http.proxyUser", authUser);
System.setProperty("http.proxyPassword", authPassword);

Authenticator.setDefault(
 
new Authenticator() {
   
public PasswordAuthentication getPasswordAuthentication() {
     
return new PasswordAuthentication(authUser, authPassword.toCharArray());
   
}
 
}
);

--
Prateek Chandra Jha2nd Year Undergraduate | Aerospace Engineering | +919004076998

The feeling that ‘no one is listening to me’ make us want to spend time with machines that seem to care about us.

Saswat Padhi

unread,
Jul 13, 2012, 4:32:42 PM7/13/12
to wncc...@googlegroups.com
I think you might find this helpful: http://stackoverflow.com/questions/8669726/java-proxy-authentication

It actually used basic HTTP Auth to tackle the proxy.

--
The website for the club is http://stab-iitb.org/wncc
To post to this group, send email to wncc...@googlegroups.com

Prateek Chandra Jha

unread,
Jul 13, 2012, 6:47:48 PM7/13/12
to wncc...@googlegroups.com
By the way does Windows still make or rely on use of NTLM proxy (because this stackflow is on NTLM authentication problem) ? 
What was the major diference between kerberos and NTLM ?

The answer is slightly vague because It is not a solution but a snippet of code that accompanies the code I provided above.

and the error I am getting is HTTP 403 which is a forbidden status code.

I think because it is not giving any errors, it might be some everlasting eclipse bug. I am not sure. Lets see.

Guna Prasaad

unread,
Jul 14, 2012, 3:26:08 AM7/14/12
to wncc...@googlegroups.com
You can also try out HtmlUnit library for connections using proxy authentication. It's simple and easy API. 

Sent from my iPad
Reply all
Reply to author
Forward
0 new messages