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

  • Home
  • SEARCH
  • 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 8187013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:25:10+00:00 2026-06-07T02:25:10+00:00

I was able log in through my android app to http://yearbook08.com/ using this code:

  • 0

I was able log in through my android app to http://yearbook08.com/ using this code:

    String URL="http://yearbook08.com/login.php";

    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = null;


    HttpPost httppost = new HttpPost(URL); 
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("userId", uname));
    nameValuePairs.add(new BasicNameValuePair("password", pass));
    try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }



    try {
        response = httpclient.execute(httppost);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Now when I move to another activity I want to retrieve http://yearbook08.com/wall.php but the web server does not recognize my last login and asks me to login again.

Is there a way that I can stay logged in after once logging in? Kindly help !

  • 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-06-07T02:25:12+00:00Added an answer on June 7, 2026 at 2:25 am

    Your code does not take into account session management. This happening as after a successful login no cookies are set, so if you send another request the initial authentication is lost and server takes it to be a fresh request.
    I would suggest you use Apache httpcomponents library 4.x (httpclient in particular)

    Create a httpcontext and attach a cookie store as

    // Create a local instance of cookie store
    CookieStore cookieStore = new BasicCookieStore();
    // Create local HTTP context
    HttpContext localContext = new BasicHttpContext();
    // Bind custom cookie store to the local context
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    HttpGet httpget = new HttpGet("http://www.google.com/"); 
    // Pass local context as a parameter
    HttpResponse response = httpclient.execute(httpget, localContext);
    

    Make use the same localContext in the subsequent requests. Also note cookiestore and httpcontext should be declared as static or global variables as their scope must exist wherever you carry the httprequest. You don’t have to set cookies on your own, it is automatically done!
    And do read about HttpComponents 4.x http://hc.apache.org/httpcomponents-client-ga/index.html

    Update 1:
    Make sure it is v4 and v3. basicCookiestore has only been present since v4. It is clear now that you are using v3 which does not know about basiccookiestore object. Add the v4 library to your project. It will solve your problem

    Update 2
    If you try to retrieve http://yearbook08.com/wall.php from the 2nd activity this problem will arise as the 2nd activity won’t have httpcontext,httpclient or the Cookiestore object in it. So it will send a fresh request.
    1st approach
    So you should try to fetch the contents you need in the first activity itself and then pass on the fetched data to the 2nd activity. This way you’ll have session maintained.
    2nd soln
    If you are not satisfied with this you can check this out http://www.jameselsey.co.uk/blogs/techblog/android-implementing-global-state-share-data-between-activities-and-across-your-application/ Share httpcontext, cookiestore and httpclient across the activities to accomplish the task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to log users out of my app built in
In the file http://example.com/path/foo.php , I have the form (formatting deleted): <form action=/path/foo.php method=post>
Any way to do this? Cause it keeps indexing and searching through my log
I need to be able to traverse through my entire object graph and log
I want to be able to log in to a site automatically. For that
I want to be able to log all JMX data accessible via jconsole. Is
I have a situation where ideally I want to be able to log-in to
I am having a problem with my crawler. I was able to log in
Not able to store all binary data values into sqlite3 table using QT. For
not able to get this, can someone help for this LINQ query? select col1,

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.