Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: LWP::UserAgent destroys $response->content >:{

by iguanodon (Priest)
on May 22, 2003 at 14:23 UTC ( [id://260068]=note: print w/replies, xml ) Need Help??


in reply to Re: LWP::UserAgent destroys $response->content >:{
in thread LWP::UserAgent destroys $response->content >:{

I don't think this is an LWP::UserAgent problem. It may be something specific to the Linksys "web server". I can grab the status page from my Netgear router with no problem using this code:
#!/usr/local/bin/perl use strict; use warnings; $| = 1; use LWP::UserAgent; use HTTP::Request::Common qw(GET POST); use HTTP::Cookies; my $user = 'user'; my $pass = 'pass'; my $cookie_jar = HTTP::Cookies->new(file => '/tmp/cookie_jar', AutoSav +e => 1); my $ua = LWP::UserAgent->new(); $ua->cookie_jar($cookie_jar); my $req = GET 'http://192.168.0.1/mtenSysStatistics.html'; $req->authorization_basic($user, $pass); my $response = $ua->request($req); print $response->code . ' ' . $response->message . "\n"; my $content = $response->content; if ($content) { print $content; } else { print 'No content!'; } print "\n";

Can you give this a try (after adjusting for your environment) and see if you still get the 500 error?

Replies are listed 'Best First'.
Re: Re: Re: LWP::UserAgent destroys $response->content >:{
by SPotter (Initiate) on May 22, 2003 at 18:07 UTC
    I added the cookie jar (relavant code below)
    (I didn't spot any other functional difference)

    Same Result :{

    So, it looks like I'll have to dispense with the
    $response = $ua->request($request);
    and replace it with low level code - merde! ;)

    use AppConfig; use File::Basename; use Getopt::Long; use HTML::Form; use HTTP::Request::Common; use HTML::TreeBuilder; use HTTP::Cookies; use LWP::DebugFile ('+'); use LWP::UserAgent; use Pod::Usage; use URI::file; . . my $cookie_jar = HTTP::Cookies->new(file => '/tmp/cookie_jar', AutoSav +e => 1); my $ua; . . $ua = LWP::UserAgent->new(); $ua->agent('Mozilla/4.0'); $ua->max_size('5000'); $ua->cookie_jar($cookie_jar); . . $ua->credentials($netloc, $realm, $userid, $passwd); . . $request = HTTP::Request->new(GET => "http://192.168.1.1/Status.htm"); $response = $ua->request($request); #$response = $ua->request($request,"rspfile.html"); if ($response->is_error) { my $string; print "Error: " . $response->status_line . "\n"; print $response->error_as_HTML; $string = $response->as_string; die "$string\n"; } . .

    Steve Potter
    http://www3.sympatico.ca/steven.potter/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://260068]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found