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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:08:07+00:00 2026-05-20T21:08:07+00:00

after reading couple of resources for making HttpClient construction to perform Login over a

  • 0

after reading couple of resources for making HttpClient construction to perform Login over a form available on a website (POST method), I wrote this method:

public void connect(View v) {
    final String TAG = ">>>>>>>>>>>> Activity Log: ";
    request = new HttpGet("http://www.mysite.com/login");
    try {
        response = client.execute(request);
    } catch (ClientProtocolException e3) {
        e3.printStackTrace();
    } catch (IOException e3) {
        e3.printStackTrace();
    }

    entity = response.getEntity();
    Log.d(TAG, "Login form get: " + response.getStatusLine());
    if(entity != null) {
        try {
            entity.consumeContent();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    Log.d(TAG, "Initial set of cookies:");

    cookies = client.getCookieStore().getCookies();
    if (cookies.isEmpty())
    {
        Log.d(TAG, "None");
    }
    else
    {
        for(int i = 0; i<cookies.size(); i++)
        {
            Log.d(TAG, "- " + cookies.get(i));
        }
    }
    String action = "/login.php";
    String yourServer = "http://www.mysite.com";
    post = new HttpPost(yourServer + action);

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("username", "myuser"));
    params.add(new BasicNameValuePair("password", "mypass"));

    try {
        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e2) {
        e2.printStackTrace();
    }


    try {
        response = client.execute(post);
    } catch (ClientProtocolException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    entity = response.getEntity();

    Log.d(TAG, "Login form get: " + response.getStatusLine());
    if(entity != null){
        try {
            entity.consumeContent();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    Log.d(TAG, "Post logon cookies:");
    cookies = client.getCookieStore().getCookies();
    if (cookies.isEmpty())
    {
        Log.d(TAG, "None");
    } 
    else
    {
        for (int i = 0; i < cookies.size(); i++) {
            Log.d(TAG, "- " + cookies.get(i));
        }
    }
}

But whatever I put as username/password I get Status: “OK 200”. And as cookie I get something like this:

[version: 0][name: PHPSESSID][value:
9ismhf3p5c282p1east0drme02][domain:
.mysite.com][path: /][expiry:
null]

When I try to access some URL that is not available for not logged in users, I get the login form page. How do I know I’ve made a successful login and access the unavailable URLs?

  • 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-20T21:08:08+00:00Added an answer on May 20, 2026 at 9:08 pm

    Hey,
    I had the same problem. You are getting Status: “OK 200” because the post is deemed successful, regardless of the outcome of the login. My solution was to inspect the response entity. Essentially, this is a string containing the source of the page that your post would send a user to if done in a browser. Within this will be the page title. For example: Login Failed. While not always as aptly named as this, you can easily find the titles of both a successful login page and an unsuccessful login page by simply logging in manually and then using view -> page source.

    So, the solution would contain something like this:

    final String responseText =  EntityUtils.toString(response.getEntity());
    if (responseText.contains("<title>Login Failed<title>")
    {
    You failed
    }
    

    Hope that helps.

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

Sidebar

Related Questions

After reading a couple of answers and comments on some SQL questions here, and
I came across couple of questions about OCL expressions. After reading some university slides
After a couple of weeks reading on this forum I thought it was time
After reading a couple of tutorials on Steganography using Java/.NET I'm under the impression
after reading through a couple similar Qs/As I haven't quite found the solution I'm
I notice this has caused confusion for several people, but after reading a couple
After reading quite a couple of questions in stackoverflow, I still can't find an
After reading the Head First Design Patterns book and using a number of other
After reading this question , I was reminded of when I was taught Java
After reading a bit more about how Gnutella and other P2P networks function, I

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.