2

I searched very long and I didn't get anything really useful for my problem. I used this as a guide, scroll down to: "3. Apache HttpClient – Automate login Google".

When you use Chrome you can look up the Cookies that are used for the current page. After login and browse on other pages of the website, those Cookies are much more than the HttpClient get after login and browsing to other pages. The HttpClient gets only two out of eleven that are shown in Chrome. Those Cookies are needed for the page because the HTML I receive contains only previews witch you get when you are not logged in.
Some of the missing Cookies are called "userauth_name", "member_id" ect. I think they are necessary for a login, right? :P.

The only things I changed from the guide-code is:
- of course the URL for login and the other page to load
- in sendPost:
the Host: post.setHeader("Host", "accounts.google.com");
the Referer: post.setHeader("Referer", "https://accounts.google.com/ServiceLoginAuth");
- in getFormParams
on my test page the form tag has no id attribute, so i made this:

    Elements forms = doc.getElementsByTag("form");
    Element loginform = null;
    for (Element inputElement : forms) {
        if (inputElement.attr("name").equals("authform"))
            loginform = inputElement;
    }
    Elements inputElements = loginform.getElementsByTag("input");

    List<NameValuePair> paramList = new ArrayList<NameValuePair>();

    for (Element inputElement : inputElements) {
        String key = inputElement.attr("name");
        String value = inputElement.attr("value");

        if (key.equals("username"))
            value = username;
        else if (key.equals("password"))
            value = password;

        paramList.add(new BasicNameValuePair(key, value));          

    }

After the Headline in the guide there are the basic steps made in code:
1. Send a GET request to get login form. (I get responecode= 200)
2. Uses jsoup html parser to grab form inputs.
3. Constructs parameters and make a POST request for authentication. (responecode= 200)
4. Send another GET request to Gmail. (responecode= 200)

Ther are no server errors or java errors.

Again the question: Why there are some Cookies missing?

1
  • I kind of solved my problem. I just added all needed Cookies manually to the Cookiestore as "new BasicClientCookie". I still would like to see a other solution than adding it manually. Commented Aug 27, 2013 at 22:53

1 Answer 1

1

Some cookies may be rejected as violating the actual cookie management policy. Usually whether or not this is the case is quite easy to find out by turning on context logging as described in this guide.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.