automate web login

From: David Byrne (dbyrne_commerce_at_yahoo.com)
Date: 11/24/03


Date: Mon, 24 Nov 2003 12:41:31 -0800 (PST)
To: beginners@perl.org

Greetings,

I used CPAN (libwww-perl) docs as my main reference
and generated the following script (trying 'content'
as well as 'authorization_basic' for user id & pw),
but keep getting "405 Method Not Allowed".

I would very much appreciate any suggestions.

Cheers,
David

#!perl -w
use LWP::UserAgent;
use HTTP::Cookies;

$ua = LWP::UserAgent->new;
$ua->cookie_jar(HTTP::Cookies->new(file =>
"lwpcookies.txt", autosave => 1));

# Create a request
my $req = HTTP::Request->new(POST =>
'http://www.gene-regulation.com/');
$req->content_type('application/x-www-form-urlencoded');

# Login
# $req->content('user=gratner&password=motley');
$req->authorization_basic('gratner', 'motley');

# Pass request to the user agent and get a response
back
my $res = $ua->request($req);

# Check the outcome of the response
if ($res->is_success) {
    open (OUT, ">out.html");
    print OUT $res->content;
}
else {
    print $res->status_line, "\n";
}

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/



Relevant Pages

  • Re: Can it be done like this (ajax)?
    ... your script wait until the request is complete. ... waiting for the response. ... Instead, to use async, you have to change ...
    (comp.lang.javascript)
  • Re: Need help with creating a web forwarding site.
    ... Yep, I was thinking about the full HTTP response (including headers, HTML code ... In this script, yes - but thinking about it again, I guess you would need to ... What you're writing is more or less a proxy: ... Let's say the second request looks like this (just speculating - I'm too lazy ...
    (perl.beginners)
  • Re: How to call another program
    ... So what do you think is going to happen when you send a GET request, ... > But it had nothing that shows how to run a script. ... >> you are accessing a URL and processing its response. ... spouting gibberish like "dlksj" just to confuse you. ...
    (comp.lang.perl.misc)
  • Re: BruteForcing?
    ... for a WebPage login attempts I recommend using a proxy like WebScarab; ... Here is a simple script that uses an existing request as a template and just replaces the request body. ... // methods you can use on Request and Response ...
    (Pen-Test)
  • Re: Validation Not Firing
    ... However, if there's no client-side validation, the script ... reference for that file is never included in the page response. ...
    (microsoft.public.dotnet.languages.csharp)