From: Marvin D. <mar...@gm...> - 2016-03-18 20:44:50
|
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 are not being sent back to the server. htmlunit is set with setUseInsecureSSL by 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("request token :" + requestToken); > > > out.println("after loginPage"); > > > > 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()){ > Cookie cookie = ite.next(); > cookie.getDomain().substring(1); > String name = cookie.getName(); > String value = 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++){ > String cookie = boxCookies.toArray()[index].toString(); > String cookieNameValue=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 HtmlPasswordInput password= (HtmlPasswordInput) loginPage2.getElementById("password"); > password.setValueAttribute(USER_PASS); > > final HtmlSubmitInput button_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("after accessGrantingPage"); > > out.println(cookieManager.getCookies().toString()); > final HtmlButton consent_accept_button = accessGrantingPage.getElementByName("consent_accept"); > > try { > final HtmlPage authorizationPage = consent_accept_button.click(); > out.println("after authorizationPage"); > out.println(authorizationPage.getUrl().toString()); > out.println(authorizationPage.getWebResponse().getStatusMessage()); > > out.println(authorizationPage.getWebResponse().getResponseHeaders()); > > } catch (RuntimeException re){ > 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 prevent sending or receiving certain types of file attachments. Check your e-mail security settings to determine how attachments are handled. |