http://www.perlmonks.org?node_id=348806

dannoura has asked for the wisdom of the Perl Monks concerning the following question:

hi,

I'm trying to automate my login to this site. It's encrypted, but I have OpenSSL, so that should be no problem. But, I keep getting 405 Method not allowed when using the code:

#! c:\perl\bin -w use strict; use LWP::UserAgent; use LWP::Protocol::https; use HTTP::Request::Common; my $ua = LWP::UserAgent->new; my $request = POST 'https://www.saxobank.com/', [ UserID => 'myID', Password => 'myPasswd', ]; my $page = $ua->request($request); if ($page->is_success) { print $page->content; } else { print $page->status_line; }

And the same when using the code:

#! c:\perl\bin -w use strict; use LWP::UserAgent; use LWP::Protocol::https; use HTTP::Request::Common; use HTTP::Cookies; # form variables my $UserID = 'myID'; my $password = 'myPasswd'; # bot variables my $agent = LWP::UserAgent->new; my $cookie_jar = HTTP::Cookies->new; my $res; # URL's of importance my $login_url = 'https://www.saxobank.com'; &login($agent, $res, $cookie_jar, $UserID, $password, $login_url); exit; sub login($$$) { my( $agent, $res, $cookie_jar, $UserID, $password, $login_url) = @_; # build request for login web page (so we get the set of cookies) my $req = POST ($login_url, [ cmd => 'login', dest => 'https://www.saxobank.com', UserID => $UserID, Password => $password, ]); # issue the request $res = $agent->request($req); if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; } # extract the cookies $cookie_jar->extract_cookies($res); }

Any ideas about how to tackle this problem?

-----------------------------------

Any comments about coding style are welcome.

Replies are listed 'Best First'.
Re: 405 error when trying to log in
by rob_au (Abbot) on Apr 28, 2004 at 13:55 UTC

    This error code indicates that the request method is not allowed for the given web address - This to my mind suggests that your web server is not configured to allow POST requests to be made against the address/location http://www.saxobank.com.

    See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6

     

    perl -le "print unpack'N', pack'B32', '00000000000000000000001011010100'"

      How do I find out if my server can or cannot POST to that site?

      -----------------------------------

      Any comments about coding style are welcome.
        You find out by trying to POST like you have. You already have your answer (method not allowed).

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: 405 error when trying to log in
by EdwardG (Vicar) on Apr 28, 2004 at 13:54 UTC

    Sounds like your request is not using SSL, which might be because your installation of SSL is broken.

    Have you got this working for any other site?

     

      Wouldn't a broken installation of SSL result in a 500 error?

        Maybe if the server you're trying to connect to has a broken installation of SSL, not if you do.

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.