title: Apache HttpClient 4.2.1 POST request to fill form after successful login
body: <p>I'm writing an application which can log in to a site and submit a certain form.
  I can successfully log in, but when I try to sent another POST request to submit another form, nothing happens. </p>
  
  <p>This is my code:</p>
  
  <pre><code>    try {
             //log in to site
          HttpPost httpPost = new HttpPost("http://mysite.ru");
          List&lt;NameValuePair&gt; nvps = new ArrayList&lt;NameValuePair&gt;();
          nvps.add(new BasicNameValuePair("login", "guest"));
          nvps.add(new BasicNameValuePair("password", "guest"));
  
          httpPost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
  
          HttpResponse response = httpClient.execute(httpPost);
  
          HttpEntity entity = response.getEntity();
          EntityUtils.consume(entity);
  
             //all ok. i obtained cookie
          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());
                  ConnectionManager.printLog("- " + cookies.get(i).toString());
              }
          }
  
              //then trying to fill another form in another page of this site
          httpPost = new HttpPost("http://mysite.ru/?h[0][mode]=controllers&amp;h[0][action]=add&amp;h[1][mode]=controllers");
  
          List&lt;NameValuePair&gt; nvps2 = new ArrayList&lt;NameValuePair&gt;();
          nvps2.add(new BasicNameValuePair("owner", "0"));
          nvps2.add(new BasicNameValuePair("imei", "123456789123456"));
          nvps2.add(new BasicNameValuePair("password", "asdfghj"));
          nvps2.add(new BasicNameValuePair("type_id", "6"));
          nvps2.add(new BasicNameValuePair("remarks", ""));
  
          httpPost.setEntity(new UrlEncodedFormEntity(nvps2));
  
          response = httpClient.execute(httpPost);
             //after filling this form, site must redirect me on another page. 
          entity = response.getEntity();
             //but then I look on page I obtained, it's still the same page with form I tried to fill. 
             //It seems like I didn't post request.
          String pageHTML = EntityUtils.toString(entity);
          System.out.println(pageHTML);
  
          EntityUtils.consume(entity);
  
      } finally {
          httpClient.getConnectionManager().shutdown();
      }
  </code></pre>
  
  <p>The second form doesn't differ from first by type.</p>