7 Replies Latest reply: Feb 19, 2013 2:37 AM by 990745 RSS

    Getting a Proxy Authentication error with HTMLUnit

    990745
      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.