Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: LWP::Simple setting a proxy

by t0mas (Priest)
on Jan 17, 2001 at 21:13 UTC ( #52549=note: print w/ replies, xml ) Need Help??


in reply to LWP::Simple setting a proxy

I usually go:

$ENV{HTTP_proxy}="http://proxy.company.com:80";
somewhere before I start getting stuff with it.

But you can also set the environment variable HTTP_proxy in your shell to http://proxy.company.com:80

/brother t0mas


Comment on Re: LWP::Simple setting a proxy
Download Code
Re: Re: LWP::Simple setting a proxy
by thealienz1 (Pilgrim) on Jan 17, 2001 at 21:20 UTC

    Thanks, but no success... I still get nope. So, maybe I am doing somethign wrong.

    use LWP::Simple; $ENV{HTTP_proxy}="http://10.2.7.11:8080"; #The username that you are looking up print "Please input username: "; $username = <STDIN>; chomp($username); #Gets URL $url = 'http://www.live365.com/cgi-bin/directory.cgi?genre=search&sear +chdesc=' . $username . '&searchfields=H'; print "$url\n"; unless (defined ($page = get($url))) { print "Cannot retrieve page... Sorry =(\n\n"; exit; } #Get Description print "Description: "; if($page =~ m|<A class="desc".*?>(.*?)</A>|) { print "$1\n"; } else{ print "No description\n"; } #Check Profile print "Profile: "; if($page =~ m|<A class="handle".*?>(.*?)</A>|) { print "$1\n"; } else{ print "No profile\n"; } #Connection Speed print "Speed: "; if($page =~ m|<TD ID="connection".*?>(.*?)</TD>|) { print "$1\n"; } else{ print "No connection\n"; } #Number of listeners print "Listeners: "; ($listen,$outof) = (0,0); if($page =~ m|DrawListenerStars("/scp/../images/", (\d+), (\d+))|) {($ +listen,$outof) = ($1,$2);} print "$listen / $outof\n";

    This is supposed to check live365.com and return the information of my radio. I know it might see like "Why are you doing this?", but when their web server is so damn slow. It makes it worth not loading their enitre page.

    I am the first overweight, very tall munchkin... be very amazed.
      Just a guess (since you gave no information on how or what is failing):

      Does your proxy, by any chance, require authentication?

      Have fun ...

      Andreas

      I bet that LWP::Simple's internal UserAgent gets created at use time, so your env variable definition is not seen.

      Just guessing (untested)... either put your env-var setting inside a BEGIN block before the use:

      BEGIN { $ENV{HTTP_proxy}="http://10.2.7.11:8080" } use LWP::Simple;
      or you can always go "behind the scenes" with LWP::Simple by accessing $LWP::Simple::ua:
      use LWP::Simple qw($ua); $ua->proxy([qw(http ftp)], 'http://10.2.7.11:8080');

      -- Randal L. Schwartz, Perl hacker

      I would like to use HTTP::Request::Common and LWP::UserAgent for that kind of stunt and use a POST to submit the data to the server.

      Try out the following:
      #!/usr/bin/perl -w # Uses use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; # URL my $url = 'http://www.live365.com/cgi-bin/directory.cgi'; # User Agent Object my $ua = LWP::UserAgent->new; $ua->proxy(['http', 'ftp'], 'http://10.2.7.11:8080'); #The username that you are looking up print "Please input username: "; my $username = <STDIN>; chomp($username); # Request my $req = POST $url, [ genre=>'search', searchdesc=> $username, searchfields=>'H']; my $page=$ua->request($req)->as_string; #The rest of your code goes here


      /brother t0mas

        I needed something fast... I needed something quick... I needed something SIMPLE... hence LWP::Simple!

        I am the first overweight, very tall munchkin... be very amazed.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2015-07-05 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls