Sébastien Maurette
2007-Oct-04 11:40 UTC
[Mechanize-users] newbie question with login form
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 ?
what''s wrong with my code ?
thanks in advance
zeb
Hey Zeb! On Thu, Oct 04, 2007 at 12:40:47PM +0100, S?bastien Maurette wrote:> 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 . >[snip]> > this application seems to use redirection and probably there is a > problem with the cookies session ? > what''s wrong with my code ?Your code looks fine! There could be a couple issues that I can think of right of the bat. First, make sure that you are submitting all of the correct data. The way that I typically verify this is by using the livehttpheaders plugin for Firefox (firebug may work as well), and comparing what live httpheaders says to what my mechanize log says. http://livehttpheaders.mozdev.org/ Second, is there javascript on the page that modifies some of the input fields? If so, you''ll need to reproduce its functionality. I hope that helps! -- Aaron Patterson http://tenderlovemaking.com/
Sébastien Maurette
2007-Oct-04 16:53 UTC
[Mechanize-users] newbie question with login form
hi aaron, thanks for your help ! i checked my httpheaders and didn''t find any problem... but just a question, i can see a '' pmv_ck_session '' and a ''pmv_ck_view_conf'' cookies in response-header: set-cookie. and in request_header i just have one of both, request-header: cookie => pmv_ck_view_conf=YToxOntzOjQ6ImxhbmciO3M6MTI6ImZyLXV0Zi04LnBocCI7fQ%3D%3D maybe application is waitting for this cookie to authenticate me ? how to add the '' pmv_ck_session '' session cookie on each request ? Aaron Patterson a ?crit :> Hey Zeb! > > On Thu, Oct 04, 2007 at 12:40:47PM +0100, S?bastien Maurette wrote: > >> 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 . >> >> > [snip] > >> this application seems to use redirection and probably there is a >> problem with the cookies session ? >> what''s wrong with my code ? >> > > Your code looks fine! There could be a couple issues that I can think > of right of the bat. First, make sure that you are submitting all of > the correct data. The way that I typically verify this is by using the > livehttpheaders plugin for Firefox (firebug may work as well), and > comparing what live httpheaders says to what my mechanize log says. > > http://livehttpheaders.mozdev.org/ > > Second, is there javascript on the page that modifies some of the input > fields? If so, you''ll need to reproduce its functionality. > > I hope that helps! > >