PSCO
PSCO

Reputation: 11

Problems with Perl Mechanize and Proxies

I've been frustrating myself with this for way too many hours. I think this should be simple but I obviously have something fundamental wrong. I've read:

I've read the cpan docs for : WWW-Mechanize/lib/WWW/Mechanize/FAQ.pod libwww-perl-5.837/lib/LWP/UserAgent.pm

And every bit of sample code or article I could find on Google.

This is my first time looking for help on Stack Overflow. Thanks for your help in advance. Here is the code:

#!/usr/bin/perl

use WWW::Mechanize;

my $mech = WWW::Mechanize->new ( agent => "Mozilla/5.0" );

my $proxy = 'http://fetch4.me';

$mech->no_proxy('localhost');
$mech->proxy(['http', 'https', 'gopher'], $proxy) or die $!;
$mech->get('http://www.google.com');

print $mech->uri(),"\n";
print $mech->content(),"\n";
print $mech->text(),"\n";
print $mech->status(),"\n";

Here is the output:

http://www.google.com
<html>Apache is functioning normally</html>

Apache is functioning normally
200

I'm running out of ideas here. Does this code work for you? Does it produce the same results? What's wrong with it? >.<

Thank you for your time.

Upvotes: 1

Views: 1745

Answers (2)

Olod
Olod

Reputation: 139

The problem seems to be in the server fetch4.me. Try, for instance, instead

my $proxy = 'http://124.207.162.87:80';

Upvotes: 2

ysth
ysth

Reputation: 98398

Does saying:

my $mech = WWW::Mechanize->new ( agent => "Mozilla/5.0", noproxy => 1 );

help?

The doc implies you need to do that to avoid an implicit call to LWP's env_proxy.

Upvotes: 1

Related Questions