Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

LWP::Simple request through a proxy

by freak
on May 04, 2004 at 10:53 UTC ( #350285=perlquestion: print w/ replies, xml ) Need Help??
freak has asked for the wisdom of the Perl Monks concerning the following question:

will this code make an LWP::Simple requst throgh LWP::UserAgent proxy ? :
require LWP::UserAgent; use LWP::Simple; my $ua = LWP::UserAgent->new; $ua->timeout(5); $ua->cookie_jar({ file => "$ENV{'HOME'}/lwp_cookies.dat" }); $x = "google.com"; $ua->proxy('http', "http://$x"); $content = get("http://flash.udaff.com/"); die "Couldn't get it!" unless defined $content; print "Done\n";

Edit by Corion: I had to put <code> ... </code> tags around the parts of the post to make these look like Perl code. The advantage of doing so is that the post looks much better, both in the preview and in the final post.

Comment on LWP::Simple request through a proxy
Download Code
Re: LWP::Simple request through a proxy
by dave_the_m (Parson) on May 04, 2004 at 11:11 UTC
    Well, the code looks plausible, except that the value in $x should be the URL of the proxy server, while the argument to get() should be the URL of the site you want to get from.
      is this better ? :
      require LWP::UserAgent; use LWP::Simple; my $ua = LWP::UserAgent->new; $ua->timeout(5); $ua->cookie_jar({ file => "$ENV{'HOME'}/lwp_cookies.dat" }); $ua->proxy('http', "http://google.com"); $content = get("http://flash.udaff.com/"); die "Couldn't get it!" unless defined $content; print "Done\n";

      Edited by Chady -- added code tags.

        Learn to format your text using <code> blocks or I'll stop responding to your posts.

        google.com is not a proxy server.

Re: LWP::Simple request through a proxy
by Abigail-II (Bishop) on May 04, 2004 at 12:05 UTC
    Your code isn't doing an LWP::Simple request. It's doing its request through LWP::UserAgent (LWP::Simple will use LWP::UserAgent itself as well). Do one to three things:
    • Forget about LWP::Simple. You seem to cope with LWP::UserAgent fine.
    • Use LWP::Simple, and have it export $ua. Set up the proxy through $au, as in your code (But the method above is just as easy).
    • Either use LWP::UserAgent or LWP::Simple as described above, and setup the proxy using environment variables and a call to $au -> env_proxy.
    Futher note that the second argument of the proxy method must be the proxy you are using - not the site you want to reach via a proxy.

    Abigail

      ok, How to make LWP::Simple to use a proxy (without LWP::UserAgent) OR what should the script be if LWP::Simple uses an LWP::UserAgent proxy ?
        You asked this question in this newer node: Re: How to make LWP::Simple use a proxy?, it's answered there.

        PS: try to make all your node-titles a bit more descriptive. In my opinion LWP::Simple request through a proxy is a good example of a node title, Connections is not.

      Step two above is exactly what I wanted but I wasn't quite sure exactly what was required but I am now so for others for future reference:
      # use proxy (comment out if not) my %proxy = ( host => 'http://proxy:8080' ); use LWP::Simple qw(mirror RC_OK RC_NOT_MODIFIED $ua); $ua->proxy(http => "$proxy{host}") if (defined $proxy{host});
      You can see I'm just interested in using mirror.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://350285]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2014-08-21 17:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (139 votes), past polls