From: Ahmed A. <asa...@ya...> - 2016-03-19 21:37:42
|
Hi Marvin, You usually put log4j.properties in your project path, and configure it accordingly. Anyhow, your case fails because of 404, I am not sure if you get a different result. Also, by enabling HtmlUnit to throw JavaScript errors, there is error because NativeError.stack is not yet implements [1], and this is a known issue. Yours,Ahmed [1] https://sourceforge.net/p/htmlunit/code/HEAD/tree/trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeErrorTest.java#l34 From: Marvin Desrosiers <mar...@gm...> To: htm...@li... Sent: Friday, March 18, 2016 9:44 PM Subject: [Htmlunit-user] Fwd: Emailing: HTML-Email.html Ahmed,I tried enabling the logger by adding:Logger. getLogger("org.apache.http.headers").setLevel(Level.ALL); But I didn't see any change. I've provided the credentials below.Thank you,-Marvin USER_EMAIL = ric...@gm...USER_PASS = htmlunit AUTHORIZE_LOCATION = https://app.box.com/api/oauth2/authorize?response_type=code&client_id=tr0z0beizpf2zutquoy0heainecgq7s0&redirect_uri=http://127.0.0.1&state=unused Begin forwarded message: To: mar...@gm... Subject: Emailing: HTML-Email.html Hi Marvin, You can enable the logger of "org.apache.http.headers"in log4j.properties [1] so see what HtmlUnit is sending. Otherwise you need to provide more details,including the URL and credentials, for others to look reproduce the issue. Ahmed [1] https://sourceforge.net/p/htmlunit/code/HEAD/tree/trunk/htmlunit/src/test/resources/log4j.properties From: Marvin Desrosiers <mar...@gm...> To: htm...@li... Sent: Friday, March 18, 2016 6:43 PM Subject: [Htmlunit-user] Sending Cookies in HTTP header I'm trying to understand why the cookie arenot being sent back to the server. htmlunit is set with setUseInsecureSSLby default to false for the secure tag. try { WebClient webClient= newWebClient(BrowserVersion.CHROME); /*webClient.getOptions().setUseInsecureSSL(false);*/ /*webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);*/ webClient.getOptions().setCssEnabled(false); webClient.getOptions().setJavaScriptEnabled(false); CookieManager cookieManager=webClient.getCookieManager(); out.println(cookieManager.getCookies().toString()); out.println("start"); final HtmlPage loginPage= webClient.getPage(AUTHORIZE_URL); String requestToken = loginPage.getElementByName("request_token").getAttribute("value"); out.println("requesttoken :" + requestToken); out.println("afterloginPage"); out.println(cookieManager.getCookies().toString()); Set<Cookie> boxCookies= newHashSet<Cookie>(); boxCookies.addAll(webClient.getCookieManager().getCookies()); StringBuilder cookieHeader =newStringBuilder(); /*Iterator<Cookie> ite= boxCookies.iterator(); while (ite.hasNext()){ Cookiecookie = ite.next(); cookie.getDomain().substring(1); Stringname = cookie.getName(); Stringvalue = cookie.getValue(); System.out.println("Cookie:"+ name + "=" +value); if()){ cookieHeader.append(name + "=" +value); } cookieHeader.append(";"+ name + "=" +value); } */ webClient.addRequestHeader("Accept-Encoding","gzip, deflate, sdch"); webClient.addRequestHeader("Accept-Language","en-US,en;q=0.8"); webClient.addRequestHeader("Cache-Control","no-cache"); webClient.addRequestHeader("Upgrade-Insecure-Requests","1"); webClient.addRequestHeader("DNT","1"); webClient.addRequestHeader("Host","app.company.com"); for (int index= 0; index < boxCookies.size(); index++){ Stringcookie = boxCookies.toArray()[index].toString(); StringcookieNameValue=cookie.substring(0, cookie.indexOf(";")); String name = cookieNameValue.substring(0,cookieNameValue.indexOf("=")); String value =cookieNameValue.substring(cookieNameValue.indexOf("=") + 1); if(index == 0){ cookieHeader.append(name + "=" +value); }else { cookieHeader.append("; "+ name + "="+value); } } WebRequest secondLoginPage =newWebRequest(AUTHORIZE_URL); secondLoginPage.setAdditionalHeader("Cookie",cookieHeader.toString()); HtmlPage loginPage2 = webClient.getPage(secondLoginPage); out.println(loginPage2.getWebResponse().getWebRequest().getRequestParameters().toString()); out.println("\n"); Map<?, ?> additionalRequest1= loginPage2.getWebResponse().getWebRequest().getAdditionalHeaders(); Iterator<?> ite0 = additionalRequest1.entrySet().iterator(); while(ite0.hasNext()){ out.println(ite0.next()); } out.println("\n"); final HtmlTextInput login= (HtmlTextInput) loginPage2.getElementById("login"); login.setValueAttribute(USER_EMAIL); final HtmlPasswordInputpassword= (HtmlPasswordInput) loginPage2.getElementById("password"); password.setValueAttribute(USER_PASS); final HtmlSubmitInputbutton_submit = loginPage2.getElementByName("login_submit"); final HtmlPage accessGrantingPage= button_submit.click(); final HtmlForm requestForm= (HtmlForm)accessGrantingPage.getElementById("consent_form"); Map<?, ?> additionalRequest= accessGrantingPage.getWebResponse().getWebRequest().getAdditionalHeaders(); out.println("\n"); Iterator<?> ite2 = additionalRequest.entrySet().iterator(); while(ite2.hasNext()){ out.println(ite2.next()); } out.println("\n"); out.println("afteraccessGrantingPage"); out.println(cookieManager.getCookies().toString()); final HtmlButton consent_accept_button= accessGrantingPage.getElementByName("consent_accept"); try { finalHtmlPage authorizationPage = consent_accept_button.click(); out.println("afterauthorizationPage"); out.println(authorizationPage.getUrl().toString()); out.println(authorizationPage.getWebResponse().getStatusMessage()); out.println(authorizationPage.getWebResponse().getResponseHeaders()); } catch (RuntimeExceptionre){ re.printStackTrace(); } webClient.closeAllWindows(); } catch (IOException ioe){ ioe.printStackTrace(); } finally { } Your message is ready to be sent with the following file or link attachments: HTML-Email.html Note: To protect against computer viruses, e-mail programs may preventsending or receiving certain types of file attachments. Check youre-mail security settings to determine how attachments are handled. ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140 _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user |