in reply to Re: Re: Re: Redirecting Forms with WWW::Mechanize
in thread Redirecting Forms with WWW::Mechanize

Andy, Can you tell me how mech-dump works? I'm trying to post a reply to a friends forum. I get the page like this
get("http://user:passwd\@www.somesite.com/subdir/_vti_bin/shtml.exe/po +st.htm?474")
I checked response() and this works fine. I get the form and fill in the field like this.
$w->form_number(1); $w->field('Comments', 'woo-hoo');
Again, this works fine. The button to post the reply isn't named so I do this.
$w->submit_form();
Then I check the response
my $r = $w->response(); print 'error_as_HTML: '.$r->error_as_HTML."\n";
and get a "401 Authorization Required" error.

I think the problem is that the ?474 in the url is a dynamic number assigned by the shtml code. That's one thing I have NO idea how to automate. I don't know the logic on how Microsoft generates that number or on how I can make the post.

Do you have any idea? Or can you point me in the right direction? I've given up.

Thanks,
monktim

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Redirecting Forms with WWW::Mechanize
by petdance (Parson) on Oct 09, 2003 at 02:48 UTC
    If that 474 is handed to you from MS, then you need to back up a level to the part of the transaction where you DO get that URL.

    As to how mech-dump works, just call "mech-dump --forms URL"

    xoxo,
    Andy

      Thanks Andy,

      I installed WWW:Mechanize by just downloading the code, I didn't get the zip which included mech-dump. I found the mech-dump on CPAN and it works like a champ. Thanks.

      I found out why my post wasn't working. When I turned on LWP debugging I saw that the user name and password weren't included in the URI for the submit(). The debug output looked somethig like this.

      LWP::UserAgent::new: () LWP::UserAgent::proxy: http http://xxx.xx.xx.xx:8080 LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking www.site.com for cookies HTTP::Cookies::add_cookie_header: Checking .site.com for cookies HTTP::Cookies::add_cookie_header: Checking site.com for cookies HTTP::Cookies::add_cookie_header: Checking .com for cookies LWP::UserAgent::send_request: GET http://user:pwd@www.site.com/dir/_vt +i_bin/shtml.exe/post.htm?474 LWP::UserAgent::_need_proxy: Proxied to http://xxx.xx.xx.xx:8080 LWP::Protocol::http::request: () LWP::Protocol::collect: read 808 bytes LWP::Protocol::collect: read 1001 bytes LWP::UserAgent::request: Simple response: OK LWP::UserAgent::request: () HTTP::Cookies::add_cookie_header: Checking www.site.com for cookies HTTP::Cookies::add_cookie_header: Checking .site.com for cookies HTTP::Cookies::add_cookie_header: Checking site.com for cookies HTTP::Cookies::add_cookie_header: Checking .com for cookies LWP::UserAgent::send_request: POST http://www.site.com/dir/_vti_bin/sh +tml.exe/post.htm?474 LWP::UserAgent::_need_proxy: Proxied to http://xxx.xx.xx.xx:8080 LWP::Protocol::http::request: () LWP::Protocol::collect: read 397 bytes LWP::UserAgent::request: Simple response: Unauthorized
      I thought that since I did the get() with the user:pwd that the post would include it too. Do you know how I can fix this using Mechanize? Here is a code snippet, the first commented out block worked, the second doesn't.
      use strict; use warnings; use WWW::Mechanize; # Post article works! #my $mech = WWW::Mechanize->new(); #$mech ->get('http://user:pwd@www.site.com/dir/post.htm'); #$mech ->form_number(1); #$mech ->field('Subject', 'test'); #$mech ->field('Comments', 'test'); #$mech ->click(); #Reply article fails! LWP::Debug::level('+'); my $mech = WWW::Mechanize->new(); $mech->get('http://user:pwd@www.site.com/dir/_vti_bin/shtml.exe/post.h +tm?474'); $mech->form_number(1); $mech->field('Comments', 'woo-hoo'); my $response = $mech->submit(); if ($response->is_success) { print $response->content; } else { print $response->status_line."\n"; } exit 0;
      Thanks in advance,
      monktim