title: How to extract the URL following an HTTPPost in Android
body: <p>I'm scratching my head at this problem that I can't seem to figure out. What I'm trying to do is extract the URL following the HTTPpost. This will allow me to go through the Oauth process.</p>
  
  <p>Currently I'm extracting the whole website into my entity.</p>
  
  <p>For example: The data will be posted to <a href="https://mysite.com/login" rel="nofollow">https://mysite.com/login</a> and will redirect after the post to <a href="https://mysite.com/dashboard?code=3593085390859082093720" rel="nofollow">https://mysite.com/dashboard?code=3593085390859082093720</a></p>
  
  <p>How does one extract the url?</p>
  
  <p>If you need any more information or can direct me in the right direction, all is appreciated! Thank you!</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.ResponseHandler;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.BasicResponseHandler;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class LoginActivity extends Activity implements OnClickListener {
  
  Button ok,back,exit;
  TextView result;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.login);
  
      // Login button clicked
      ok = (Button)findViewById(R.id.submit);
      ok.setOnClickListener(this);
  
      result = (TextView)findViewById(R.id.result);
  
  }
  
  public void postLoginData() {
      // Create a new HttpClient and Post Header
      HttpClient httpclient = new DefaultHttpClient();
  
      HttpPost httppost = new HttpPost("https://mysite.com/login");
  
      try {
          // Add user name and password
       EditText uname = (EditText)findViewById(R.id.username);
       String username = uname.getText().toString();
  
       EditText pword = (EditText)findViewById(R.id.password);
       String password = pword.getText().toString();
  
          List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
          nameValuePairs.add(new BasicNameValuePair("pseudonym_session[unique_id]", username));
          nameValuePairs.add(new BasicNameValuePair("pseudonym_session[password]", password));
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
          // Execute HTTP Post Request
          Log.w("CANVAS", "Execute HTTP Post Request");
          HttpResponse response = httpclient.execute(httppost);
  
          String str = inputStreamToString(response.getEntity().getContent()).toString();
          Log.w("CANVAS", str);
  
          ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); 
          String ResponseBody = httpclient.execute(httppost, responseHandler);
  
          Intent intent = new Intent(getBaseContext(), DashboardActivity.class);
          startActivity(intent);
  
          if(str.toString().equalsIgnoreCase("true"))
          {
           Log.w("CANVAS", "TRUE");
           result.setText("Login successful");   
          }else
          {
           Log.w("CANVAS", "FALSE");
           result.setText(ResponseBody); 
          }
  
      } catch (ClientProtocolException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      }
  } 
  
  private StringBuilder inputStreamToString(InputStream is) {
   String line = "";
   StringBuilder total = new StringBuilder();
   // Wrap a BufferedReader around the InputStream
   BufferedReader rd = new BufferedReader(new InputStreamReader(is));
   // Read response until the end
   try {
    while ((line = rd.readLine()) != null) { 
      total.append(line); 
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
   // Return full string
   return total;
  }
  
  @Override
  public void onClick(View view) {
    if(view == ok){
      postLoginData();
    }
  }
  
  }
  </code></pre>