Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting a Proxy Authentication error with HTMLUnit

990745Feb 13 2013 — edited Feb 19 2013
Hi,

I am using HTML Unit to automate a Google Search. I am using the proxy server of my organisation. The following lines of code

final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10, "10.122.3.98", 80);

//set proxy username and password
final DefaultCredentialsProvider credentialsProvider = (DefaultCredentialsProvider) webClient.getCredentialsProvider();
credentialsProvider.addCredentials("mysusername", "mypassword");

final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
System.out.println(page);

webClient.closeAllWindows();

gives me the error "407 Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ) for http://htmlunit.sourceforge.net/". I am supplying my username and password to the defaultCredentialsProvider. I also tried setting System property for proxyPort and ProxyHost as follows

System.setProperty("http.proxyHost","10.122.3.98");
System.setProperty("http.proxyPort","80");

but I guess HTMLUnit uses httpclient internally for authentication which ignores the JVM flags. Can anybody give me some pointers on the solution.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2013
Added on Feb 13 2013
7 comments
2,975 views