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

Dear Monks,

I'm trying to log in to a site using a script. The problem is that I keep getting 500 Can't connect to www.saxobank.com:80 (connect: Unknown error). The strange thing is that I only get this error when trying sites using authentication (which I guess means this is not a proxy issue). I've tried several with the same result. My code is below. The error is generated immediately after the GET request. As far as I can tell the POST works fine. Does anyone know what could be the problem?

#! c:\perl\bin -w use strict; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; use LWP::Debug qw(+); use LWP::Protocol::https; use Crypt::SSLeay; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1) +); # configure LWP::UserAgent to follow redirects after POST push @{ $ua->requests_redirectable }, 'POST'; my $request=$ua->request( POST "https://www.saxobank.com/Default.aspx/?id=2&Lan=EN&Au=1&Grp=5" +, { __VIEWSTATE => 'dDwtMTE1ODc1NzA2NTs7PjAuMSDgHjTB0rV7byCH14/dWkMm', txtUID => 'myID', txtPWD => 'myPass', submit => 'log in' }); print $request->is_success ? $request->content : "failed\n"; $request= $ua->request(GET "http://www.saxobank.com/?ID=101"); print $request->is_success ? $request->content : $request->status_line +;

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

Any comments about coding style are welcome.

Replies are listed 'Best First'.
Re: 500 error attempting to log in
by inman (Curate) on May 11, 2004 at 18:21 UTC
    This node should help you out if you are using https and a proxy. The basic answer is that LWP doesn't work with https and proxy servers. leira posted the work around.
Re: 500 error attempting to log in
by idsfa (Vicar) on May 11, 2004 at 17:16 UTC

    You may want to confirm that your cookies are being properly set in the response from the login page (presumably the reason you set up a cookie jar and post the login). After the initial POST, check out $request->as_string to make sure that you are receiving the expected cookies and then print out $ua->cookie_jar->as_string to confirm that they are getting into your cookie jar. Especially look for headers which expire your cookies immediately.


    If anyone needs me I'll be in the Angry Dome.