Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:36:06+00:00 2026-05-31T05:36:06+00:00

I’m scratching my head at this problem that I can’t seem to figure out.

  • 0

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.

Currently I’m extracting the whole website into my entity.

For example: The data will be posted to https://mysite.com/login and will redirect after the post to https://mysite.com/dashboard?code=3593085390859082093720

How does one extract the url?

If you need any more information or can direct me in the right direction, all is appreciated! Thank you!

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<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(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<String> 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();
  }
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:36:07+00:00Added an answer on May 31, 2026 at 5:36 am

    if you set a redirect handler, you can get back from the response the location the server’s sending you to. here’s a snippet of code I was just playing with… (and I should point out, if you DON’T set a redirect handler, you’ll just get redirected to the final destination, which might be the login screen itself)

    DefaultHttpClient htc = getHttpClient();
    htc.setRedirectHandler(new RedirectHandler() {
      @Override
      public boolean isRedirectRequested(HttpResponse response, HttpContext context)
      {
        Log.d(TAG, "isRedirectRequested, response: " + response.toString());
        return false;
      }
    
      @Override
      public URI getLocationURI(HttpResponse response, HttpContext context)
          throws ProtocolException
      {
        Log.d(TAG, "getLocationURI, response: " + response.toString());
        return null;
      }
    });
    HttpResponse resp = null;
    StringBuilder out = new StringBuilder();
    try
    {
      HttpGet get = new HttpGet(spec);
      resp = htc.execute(get);
      for (Header hdr : resp.getAllHeaders())
        Log.d(TAG, "header " + hdr.getName() + " -> " + hdr.getValue());
      ...
    }
    catch (Exception e)
    {
      Log.e(TAG, "Error connecting to " + spec, e);
      return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.