From: Ahmed A. <asa...@ya...> - 2015-02-17 12:43:52
|
Hi, Interestingly, real FF31 ESR and IE11 behind proxy show the same error message, but Chrome doesn't. This could be a bug in HtmlUnit chrome implementation, but FF31 and IE11 match real browser behavior. You can investigate further by turning header logging as hinted in :http://htmlunit.sourceforge.net/logging.html log4j.logger.org.apache.http.headers=debuglog4j.logger.org.apache.http.wire=debug Hope that helps,Ahmed From: Dr. Britta Landgraf <b.l...@fz...> To: htm...@li... Sent: Tuesday, February 17, 2015 1:17 PM Subject: [Htmlunit-user] enable cookies failed Hi, I will login to a https page which needs cookies enabled. I set it in the CookieManager, but I get always the awnser that cookies aren't enabled :( I'm using htmlunit 2.15. My code: private final WebClient webClient; public LoginPage() { this.webClient = new WebClient(BrowserVersion.FIREFOX_24); webClient.getOptions().setJavaScriptEnabled(true); webClient.getCookieManager().setCookiesEnabled(true); } public void loginAs(String username, String password, String domain) throws FailingHttpStatusCodeException, MalformedURLException, IOException { System.out.println(webClient.getCookieManager().isCookiesEnabled()); // Get the login page HtmlPage loginPage = (HtmlPage) webClient .getPage("https://users.euro-fusion.org/cfjec-authenticate"); String htmlBody = loginPage.getWebResponse().getContentAsString(); System.out.println(htmlBody); // Get the form that we are dealing with and within that form, // find the submit button and the field that we want to change. HtmlForm form = loginPage.getForms().get(0); // Enter login and passwd form.getInputByName("user").setValueAttribute(username); form.getInputByName("password").setValueAttribute(password); HtmlSelect select = (HtmlSelect) loginPage.getElementByName("domain"); HtmlOption option = select.getOptionByValue(domain); select.setSelectedAttribute(option, true); // Click "Sign In" button HtmlPage page1 = (HtmlPage) form.getInputByValue("Log In").click(); // Get page as Html htmlBody = page1.getWebResponse().getContentAsString(); System.out.println(htmlBody); } public static void main(String args[]) { LoginPage pb = new LoginPage(); // make sure cookies is turn on CookieHandler.setDefault(new CookieManager()); try { pb.loginAs("xxx", "yyy", "EXTERNAL"); } catch (FailingHttpStatusCodeException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } ------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------ Forschungszentrum Juelich GmbH 52425 Juelich Sitz der Gesellschaft: Juelich Eingetragen im Handelsregister des Amtsgerichts Dueren Nr. HR B 3498 Vorsitzender des Aufsichtsrats: MinDir Dr. Karl Eugen Huthmacher Geschaeftsfuehrung: Prof. Dr.-Ing. Wolfgang Marquardt (Vorsitzender), Karsten Beneke (stellv. Vorsitzender), Prof. Dr.-Ing. Harald Bolt, Prof. Dr. Sebastian M. Schmidt ------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |