title: HttpClientFormSubmit to get the OAUTH access token
body: <p>I am using httpcomponents-client-4.2.5-bin for the ClientFormSubmit. I used the <a href="https://stackoverflow.com/questions/1902013/apache-httpclient-to-access-facebook">example</a> to login to facebook using Oauth. My Oauth login has following steps</p>
  
  <ol>
  <li><p>first login to facebook using </p>
  
  <p><a href="https://www.facebook.com/dialog/oauth?client_id=xxxxxxx&amp;redirect_uri=http://localhost:8080/" rel="nofollow noreferrer">https://www.facebook.com/dialog/oauth?client_id=xxxxxxx&amp;redirect_uri=http://localhost:8080/</a>  </p></li>
  <li><p>give the login details it redirects to the local host and have code parameter in url</p></li>
  </ol>
  
  <p>I need to get that code value.</p>
  
  <p>Code is </p>
  
  <pre><code> try {
          DefaultHttpClient httpclient = new DefaultHttpClient();
  
          HttpGet httpget = new HttpGet("https://www.facebook.com/dialog/oauth?client_id=358300034293206&amp;redirect_uri=http://localhost:8080/");
  
          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("https://www.facebook.com/dialog/oauth?client_id=358300034293206&amp;redirect_uri=http://localhost:8080/");
  
          List &lt;NameValuePair&gt; nvps = new ArrayList &lt;NameValuePair&gt;();
          nvps.add(new BasicNameValuePair("email", "*****"));
          nvps.add(new BasicNameValuePair("pass", "*****"));
  
          httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
  
          response = httpclient.execute(httpost);
          entity = response.getEntity();
          System.out.println("Double check we've got right page " + EntityUtils.toString(entity));
  
          System.out.println("Login form get: " + response.getStatusLine());
          if (entity != null) {
              entity.consumeContent();
          }
  
          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();
      }catch(Exception e)
          {
              System.out.println( "Something bad just happened." );
              System.out.println( e );
              e.printStackTrace();
          }
  
      }
  </code></pre>
  
  <p>Is it possible to get the redirect url using request header? Thanks In Advance.</p>