Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am assuming that you want to automate browser operations and maintain session so that you can access those pages too which need session to be maintained. </p> <p>I don't know how to this through org.apache.http.client API. If you are not restricted to use org.apache.http.client API and can use other API then you can use <a href="http://htmlunit.sourceforge.net/" rel="nofollow noreferrer">HtmlUnit</a> API otherwise you can ignore the rest of the answer.</p> <p>Maintaining sessions and automating browser operations through <a href="http://htmlunit.sourceforge.net/" rel="nofollow noreferrer">HtmlUnit</a> can be done as follows:</p> <pre><code>import com.gargoylesoftware.htmlunit.*; import com.gargoylesoftware.htmlunit.html.*; final WebClient webClient = new WebClient(); try { webClient.setJavaScriptEnabled(true); webClient.setThrowExceptionOnScriptError(false); webClient.setCssEnabled(true); webClient.setUseInsecureSSL(true); webClient.setRedirectEnabled(true); HtmlPage loginPage = webClient.getPage(new URL("https://www.orkut.com/")); System.out.println(loginPage.getTitleText()); List&lt;HtmlForm&gt; forms = loginPage.getForms(); HtmlForm loginForm = forms.get(0); HtmlTextInput username = loginForm.getInputByName("Email"); HtmlPasswordInput password = loginForm.getInputByName("Passwd"); HtmlInput submit = loginForm.getInputByName("signIn"); username.setValueAttribute("username"); password.setValueAttribute("password"); HtmlPage homePage = submit.click();. Thread.sleep(10 * 1000); HtmlPage homePageFrame = (HtmlPage) homePage.getFrameByName("orkutFrame").getEnclosedPage(); HtmlPage communitiesTestPage = (HtmlPage) webClient.openWindow(new URL("http://www.orkut.co.in/Main#Community?cmm=1"), "CommunitiesWindow").getEnclosedPage(); }catch(java.security.GeneralSecurityException e) { e.printStackTrace(); }catch(java.io.IOException e) { e.printStackTrace(); }catch(InterruptedException e) { e.printStackTrace(); } WebWindow ww = webClient.getWebWindowByName("CommunitiesWindow"); WebRequestSettings wrs1 = new WebRequestSettings(URL); // URL is the url that requires authentication first </code></pre> <p>As you can see that how the above code automate browser operations and how it maintains session automatically. We don't need to handle cookies or URLReDirect manually...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload