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 7921727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:41:38+00:00 2026-06-03T16:41:38+00:00

I have been trying to use the same HttpClient instance throughout different activities, but

  • 0

I have been trying to use the same HttpClient instance throughout different activities, but it was not working. So I decided to just try one activity and use HttpClient to log in, and then log out once the log in was successful. This is all in the same activity, so HttpClient should definitely keep the session correct?

HttpClient client = new DefaultHttpClient();
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair(UN_ID, username));
    postParameters.add(new BasicNameValuePair(PW_ID, password));

HttpPost request = new HttpPost(URL);

formEntity = new UrlEncodedFormEntity(postParameters);

request.setEntity(formEntity);

response = client.execute(request);

If the response is a successful log in, I try to log out:

if (responseCode.equals("101")){ //successful
        HttpGet g = new HttpGet("https://site.com/file.php?logout=1");
        HttpResponse r = client.execute(g);

This returns a “not logged in” response. Is this a problem with the server, HttpClient or my code?

EDIT: Response to Eric’s answer.

I have already tried this with cookies:

CookieStore cookieStore = new BasicCookieStore();
    httpContext = new BasicHttpContext();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

Then changed each response from above to include the context:

response = client.execute(request, httpContext);

HttpResponse r = client.execute(g, httpContext);
  • 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-03T16:41:40+00:00Added an answer on June 3, 2026 at 4:41 pm

    This is because cookies are not activated by default. You need to use HttpContext as described on this question: How do I manage cookies with HttpClient in Android and/or Java?


    EDIT AFTER DISCUSSION (see comments)

    Looks like the error came from a problem with the server implementation of the authentication process

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

Sidebar

Related Questions

I keep on having these same two problems. I have been trying to use
I have been trying to use Prototype to do some DOM manipulation, but I
I have been trying to set-up Maven for use in our dev department but
I have been trying to use JScrollPane with my applet, but it doesn't work.
I have been trying to plot a map on axmapcontrol and use the same
I have been trying to use the Perl utility/module "prove" as a test harness
I have been trying to use routes.rb for creating a URL /similar-to-:product (where product
I have been trying to use the hibernate dialect for SQLite from http://code.google.com/p/hibernate-sqlite/ in
I have been trying to use/save the boolean value of a checkbox in other
I have been trying to use 3rd party tool called visiblox for rendering charts

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.