From: Marc G. <mgu...@ya...> - 2015-02-17 14:22:01
|
Hi, I get following with (real) FF: ---------------- Unable to Log In This site uses cookies for its own security. Your browser must be capable of processing cookies and cookies must be activated. Please set your browser to accept cookies, then press the reload button. ---------------- this clearly means that the problem is not with accepting cookies or not. Cheers, Marc. -- HtmlUnit support & consulting from the source Blog: http://mguillem.wordpress.com Le 17/02/2015 13:17, Dr. Britta Landgraf a écrit : > 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(); > } > > } > } -- HtmlUnit support & consulting from the source Blog: http://mguillem.wordpress.com |