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

For some reason, The following code works perfectly on windows machine but fails on FreeBSD.
I have updated all the modules on FreeBSD and am running perl 5.6 1 on both machines.
The post simply fails on FreeBSD with no errors.
Any help would be greatly appreciated.

#!/usr/bin/perl use strict; print "Content-type: text/html\n\n"; $|++; use LWP; use HTTP; use HTTP; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file=>'cookie_jar', autosave=>1)); my $r = $ua->simple_request(POST "http://www.somesite.com/Login.jsp", { requiredUserName => '123abc', requiredPassword => 'abc123', 'Submit' => 'Sign in', }); while ($r->is_redirect) { my $u = $r->header('location') or die "missing location: ", $r->as_string; print "redirecting to $u\n"; $r = $ua->simple_request(GET $u); } if ($r->is_success) { print $r->content; } else{ print "failed"; } exit;

Replies are listed 'Best First'.
Re: Problems with LWP on FreeBSD
by shotgunefx (Parson) on Apr 30, 2002 at 14:57 UTC
    You should run with warnings on. I don't think that simple_request is even an actual method. Scanning through the source of my LWP it's not even there. It's a method of LWP::UserAgent. You should be using LWP::UserAgent instead of just LWP. Try something like this.
    #!/usr/bin/perl use LWP::UserAgent; use HTTP::Request::Common; my $ua = new LWP::UserAgent; my $r = $ua->request(POST 'http://www.somesite.com/Login.jsp', Submit= +>'Sign in', requiredUserName=>'123abc', requiredPassword=>'abc'); if ($res->is_success) { }else{ }


    -Lee

    "To be civilized is to deny one's nature."
Re: Problems with LWP on FreeBSD
by slloyd (Hermit) on Apr 30, 2002 at 18:09 UTC
    The problem is that we cannot seem to pass cookies. the following script works now except that it returns a page that says 'You must enable cookies'...

    #!/usr/bin/perl -w use strict; print "Content-type: text/html\n\n"; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1) +); my $r = $ua->request(POST "http://www.handango.com/Login.jsp", requiredUserName => 'abc123', requiredPassword => '123abc', Submit => 'Sign in' ); while ($r->is_redirect) { my $u = $r->header('location') or die "missing location: ", $r->as_string; $r = $ua->request(GET $u); } #print $r->as_string; if ($r->is_success) { print $r->content; } else{ print "failed"; } exit;
Re: Problems with LWP on FreeBSD
by pepik_knize (Scribe) on Apr 30, 2002 at 14:05 UTC
    Please use the warnings switch in your she-bang line like so:

    #!/usr/bin/perl -w

    Now see if there are any helpful hints, and let us know.