Session error in android httpclient

1

I'm trying to make an application to log into the college website, and through crawler I work the information returned by httpclient. Note: I'm doing it for learning, I started recently in Java.

I make several posts because the college site has redirection during login.

The error is that I authenticate, but when I do the Post from the last page, the expired session text appears on the console.

Statements:

    private AsyncHttpClient client = new AsyncHttpClient(true, 80, 443);
private PersistentCookieStore myCookieStore;

Code:

        RequestParams params = new RequestParams();
    params.put("tipo", "aluno");
    params.put("unidade", "12");
    params.put("login", "2013200111");
    params.put("senha", "???");

    client.post("http://www.unicarioca.edu.br/gvcollege_submit.php",
            params, new AsyncHttpResponseHandler() {

                @Override
                public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
                    // TODO Auto-generated method stub
                    String str = getString(arg2);
                    System.out.println(str);
                }

                @Override
                public void onFailure(int arg0, Header[] arg1, byte[] arg2,
                        Throwable arg3) {
                    // TODO Auto-generated method stub

                }
            });

    params = new RequestParams();
    params.add("lstUnidades", "1,12");
    params.add("ViewLoginXmlXsl[method]", "btnLogin_click");
    params.add("acao", "login");
    params.add("usr", "2013200111");
    params.add("passwd", "???");

    client.post(
            "https://portal.unicarioca.edu.br/index.php5?irPage=login&irModulo=aluno",
            params, new AsyncHttpResponseHandler() {

                @Override
                public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
                    // TODO Auto-generated method stub
                    String str = getString(arg2);
                    System.out.println(arg2);
                }

                @Override
                public void onFailure(int arg0, Header[] arg1, byte[] arg2,
                        Throwable arg3) {
                    // TODO Auto-generated method stub

                }
            });

    client.get(
            "https://portal.unicarioca.edu.br/modulos/aluno/login.php5?",
            new AsyncHttpResponseHandler() {

                @Override
                public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
                    // TODO Auto-generated method stub
                    String str = getString(arg2);
                    System.out.println(str);
                }

                @Override
                public void onFailure(int arg0, Header[] arg1, byte[] arg2,
                        Throwable arg3) {
                    // TODO Auto-generated method stub

                }
            });

I'll describe it step by step.

1st cookie sent by chrome- page gvcollege - no cookie return

ys-path_menu_aluno=s%3A/ynode-7/ynode-36/ynode-38; _ga=GA1.3.1594079648.1403628555; __utma=127282249.1594079648.1403628555.1409943723.1410190271.40; __utmb=127282249.1.10.1410190271; __utmc=127282249; __utmz=127282249.1408118488.24.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); PHPSESSID=17d78ba1c38aafae711f916838baa997

After sending it has a redirect, for index.php5? irPage = login ....

2nd cookie sent by chrome -

Cookie:ys-path_menu_aluno=s%3A/ynode-7/ynode-36/ynode-38; _ga=GA1.3.1594079648.1403628555; __utma=127282249.1594079648.1403628555.1409943723.1410190271.40; __utmb=127282249.1.10.1410190271; __utmc=127282249; __utmz=127282249.1408118488.24.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)

The page returns the set cookie

3 ° Set cookie

Set-Cookie:PHPSESSID=2e1dd7378b3ef2a5a6d443c9b0128f99; path=/; HttpOnly
Set-Cookie:PHPSESSID=17d78ba1c38aafae711f916838baa997; path=/; HttpOnly

And does a redirect to login.php5

4th cookie sent by chrome to college website

ys-path_menu_aluno=s%3A/ynode-7/ynode-36/ynode-38; _ga=GA1.3.1594079648.1403628555; __utma=127282249.1594079648.1403628555.1409943723.1410190271.40; __utmb=127282249.1.10.1410190271; __utmc=127282249; __utmz=127282249.1408118488.24.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); PHPSESSID=17d78ba1c38aafae711f916838baa997

5 ° Set cookie

Set-Cookie:PHPSESSID=b73d66a5f917ff9615aefd469a6fe758; path=/; HttpOnly

6th step it redirects to the student's home page.

What would these cookies ys-path_menu_aluno and others appear? I could not identify where they were set.

    
asked by anonymous 04.09.2014 / 21:46

1 answer

1

Try to save cookies before using this.

PersistentCookieStore cookieStore = new PersistentCookieStore(
            context);
((AbstractHttpClient) httpClient).setCookieStore(cookieStore);
    
05.09.2014 / 16:05