I stole the following code fragment from an example program:

use vars '@ISA';
@ISA = 'LWP::UserAgent';
my $agent    = __PACKAGE__->new;

Now I want to use a proxy and a search on CPAN to find
http://search.cpan.org/~qjzhou/LWP-UserAgent-ProxyAny-1.02/ProxyAny.pm with
some sample code (see below).

How do I modify the above fragment so I can conditionally use a proxy?

Thanks,
Sieg

use LWP::UserAgent::ProxyAny;

  my $ua = LWP::UserAgent::ProxyAny->new;
  $ua->env_proxy;   # visit url with HTTP_PROXY or Win32 IE proxy settings

  my $response = $ua->get('http://sourceforge.net/projects/bookbot');
  if ($response->is_success) {
      print $response->content;  # or whatever
  }
  else {
      die $response->status_line;
  }

  # Or set proxy by specified name

  $ua->set_proxy_by_name("No");              # No Proxy
  $ua->set_proxy_by_name("Default");         # $ua->env_proxy
  $ua->set_proxy_by_name("127.0.0.1:8080");  # set proxy as
http://127.0.0.1:8080





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to