title: HttpClient login, search and get the XML content
body: <p>I want to login to a site using <code>HttpClient</code> and after logging in I want to search for something and retrieve the contents of the search result.</p>
  
  <pre><code>/**
   * A example that demonstrates how HttpClient APIs can be used to perform
   * form-based logon.
   */
  public class TestHttpClient {
  
      public static void main(String[] args) throws Exception {
  
          DefaultHttpClient httpclient = new DefaultHttpClient();
  
          HttpGet httpget = new HttpGet("http://projecteuler.net/");
  
          HttpResponse response = httpclient.execute(httpget);
          HttpEntity entity = response.getEntity();
  
          System.out.println("Login form get: " + response.getStatusLine());
          if (entity != null) {
              entity.consumeContent();
          }
          System.out.println("Initial set of cookies:");
          List&lt;Cookie&gt; cookies = httpclient.getCookieStore().getCookies();
          if (cookies.isEmpty()) {
              System.out.println("None");
          } else {
              for (int i = 0; i &lt; cookies.size(); i++) {
                  System.out.println("- " + cookies.get(i).toString());
              }
          }
  
          HttpPost httpost = new HttpPost("http://projecteuler.net/index.php?section=login");
  
          List &lt;NameValuePair&gt; nvps = new ArrayList &lt;NameValuePair&gt;();
          nvps.add(new BasicNameValuePair("IDToken1", "username"));
          nvps.add(new BasicNameValuePair("IDToken2", "password"));
  
          httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
  
          response = httpclient.execute(httpost);
  
          System.out.println("Response "+response.toString());
          entity = response.getEntity();
  
          System.out.println("Login form get: " + response.getStatusLine());
          if (entity != null) {
  
              InputStream is = entity.getContent();
              BufferedReader br = new BufferedReader(new InputStreamReader(is));
              String str ="";
              while ((str = br.readLine()) != null){
                  System.out.println(""+str);
              }
          }
  
          System.out.println("Post logon cookies:");
          cookies = httpclient.getCookieStore().getCookies();
          if (cookies.isEmpty()) {
              System.out.println("None");
          } else {
              for (int i = 0; i &lt; cookies.size(); i++) {
                  System.out.println("- " + cookies.get(i).toString());
              }
          }
          httpclient.getConnectionManager().shutdown();        
      }
  }
  </code></pre>
  
  <p>when I print the output from <code>HttpEntity</code> it's printing the login page contents. How do I get the contents of the page after I login using <code>HttpClient</code>?</p>