newbie - mechanize multiple cookies problem with form login

Discussion in 'Ruby' started by Frioffol Friofool, Oct 4, 2007.

  1. hi,

    i'm just starting to work with this incredible tool...

    but i got a first problem with the login process

    i'm logging on my app like this :

    ------

    @agent = WWW::Mechanize.new { |a| a.log = Logger.new("mech.log") }

    @agent.user_agent_alias = 'Mac Safari'
    @page = @agent.get("http://myappAdress/")

    @form = @page.forms.first

    @form['form_login'] = 'myLog'
    @form['form_password'] = 'myPass'

    @page = @agent.submit(@form, @form.buttons.first)

    put @page.body

    ----

    Identification process is done , i can see it in my application log, but
    the page displayed is still the login form.

    here is the mechanize log .

    -----

    Net::HTTP::Get: /
    request-header: accept-language => en-us,en;q0.5
    request-header: connection => keep-alive
    request-header: accept => */*
    request-header: accept-encoding => gzip,identity
    request-header: user-agent => Mozilla/5.0 (Macintosh; U; PPC Mac OS X;
    en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3
    request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    request-header: keep-alive => 300
    Read 519 bytes
    Read 935 bytes
    Read 1959 bytes
    Read 2375 bytes
    Read 3399 bytes
    Read 3803 bytes
    response-header: connection => close
    response-header: p3p => CP='OTI DSP COR NID STP UNI OTPa OUR'
    response-header: content-type => text/html; charset=utf-8
    response-header: x-powered-by => PHP/5.1.6
    response-header: date => Thu, 04 Oct 2007 10:34:40 GMT
    response-header: server => Apache/2.2.4 (Fedora)
    response-header: content-length => 3803
    response-header: set-cookie =>
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D;
    expires=Sun, 01-Oct-2017 10:34:40 GMT,
    pmv_ck_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D;
    expires=Thu, 04-Oct-2007 11:34:40 GMT
    saved cookie:
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    saved cookie:
    pmv_ck_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D
    status: 200
    query:
    "form_login=myLog&form_password=myPass&form_url=http%3A%2F%2FmyAppUrl%2F&submit=Login+%3F"
    Net::HTTP::post: /index.php?mod=login
    using cookie:
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    request-header: accept-language => en-us,en;q0.5
    request-header: connection => keep-alive
    request-header: accept => */*
    request-header: accept-encoding => gzip,identity
    request-header: user-agent => Mozilla/5.0 (Macintosh; U; PPC Mac OS X;
    en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3
    request-header: content-type => application/x-www-form-urlencoded
    request-header: cookie =>
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    request-header: referer => http://myAppUrl/
    request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    request-header: content-length => 101
    request-header: keep-alive => 300
    Read 0 bytes
    response-header: connection => close
    response-header: p3p => CP='OTI DSP COR NID STP UNI OTPa OUR'
    response-header: content-type => text/html; charset=UTF-8
    response-header: x-powered-by => PHP/5.1.6
    response-header: date => Thu, 04 Oct 2007 10:34:41 GMT
    response-header: server => Apache/2.2.4 (Fedora)
    response-header: content-length => 0
    response-header: set-cookie =>
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D;
    expires=Sun, 01-Oct-2017 10:34:41 GMT,
    pmv_ck_session=YToyOntzOjU6ImxvZ2luIjtzOjM6InNlYiI7czo4OiJwYXNzd29yZCI7czozMjoiMGNhYzVlYWIxNWZlOWY2YTFlZmQzOGI3YzEwM2NkZDciO30%3D;
    expires=Thu, 04-Oct-2007 11:34:41 GMT
    response-header: location => myAppUrl
    saved cookie:
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    saved cookie:
    pmv_ck_session=YToyOntzOjU6ImxvZ2luIjtzOjM6InNlYiI7czo4OiJwYXNzd29yZCI7czozMjoiMGNhYzVlYWIxNWZlOWY2YTFlZmQzOGI3YzEwM2NkZDciO30%3D
    status: 302
    follow redirect to: myAppUrl
    Net::HTTP::Get: /
    using cookie:
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    request-header: accept-language => en-us,en;q0.5
    request-header: connection => keep-alive
    request-header: accept => */*
    request-header: accept-encoding => gzip,identity
    request-header: user-agent => Mozilla/5.0 (Macintosh; U; PPC Mac OS X;
    en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3
    request-header: cookie =>
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    request-header: referer => myAppUrl
    request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
    request-header: keep-alive => 300
    Read 519 bytes
    Read 935 bytes
    Read 1959 bytes
    Read 2375 bytes
    Read 3399 bytes
    Read 3803 bytes
    response-header: connection => close
    response-header: p3p => CP='OTI DSP COR NID STP UNI OTPa OUR'
    response-header: content-type => text/html; charset=utf-8
    response-header: x-powered-by => PHP/5.1.6
    response-header: date => Thu, 04 Oct 2007 10:34:41 GMT
    response-header: server => Apache/2.2.4 (Fedora)
    response-header: content-length => 3803
    response-header: set-cookie =>
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D;
    expires=Sun, 01-Oct-2017 10:34:41 GMT,
    pmv_ck_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D;
    expires=Thu, 04-Oct-2007 11:34:41 GMT
    saved cookie:
    pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D
    saved cookie:
    pmv_ck_session=YToyOntzOjU6ImxvZ2luIjtzOjk6ImFub255bW91cyI7czo4OiJwYXNzd29yZCI7YjowO30%3D
    status: 200

    -----

    this application seems to use redirection and probably there is a
    problem with the cookies session ?

    i can see a ' pmv_ck_session ' cookie and a 'pmv_ck_view_conf' sent by
    app.
    Maybe ' pmv_ck_session ' is not use correctly ?

    what's wrong with my code ?

    thanks in advance

    zeb
    --
    Posted via http://www.ruby-forum.com/.
     
    Frioffol Friofool, Oct 4, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. _Who
    Replies:
    7
    Views:
    2,726
  2. elca
    Replies:
    0
    Views:
    537
  3. elca
    Replies:
    0
    Views:
    741
  4. Pen Ttt

    mechanize login form

    Pen Ttt, Jun 16, 2010, in forum: Ruby
    Replies:
    1
    Views:
    234
    Josh Cheek
    Jun 16, 2010
  5. Pen Ttt

    mechanize login problem

    Pen Ttt, Jun 20, 2010, in forum: Ruby
    Replies:
    1
    Views:
    235
    Pen Ttt
    Jun 23, 2010
Loading...

Share This Page