Monkomatic has asked for the wisdom of the Perl Monks concerning the following question:
I am somewhat proffecient in LWP but am having difficulty getting the following proxy method to work.
I have based this solution off of Toma's LWP Quick reference guide. If anyone knows a better way to do the proxy please let me know in easy to follow code.
use LWP::Simple; use LWP::Simple qw( $ua get ); use LWP::UserAgent; use HTTP::Request::Common qw(POST); my $ua = new LWP::UserAgent; $proxy = "72.43.50.184:80"; $contentget = "http://search.cpan.org/~gaas/libwww-perl-5.837/lib/LWP/ +UserAgent.pm"; $ua->timeout(3); $ua->proxy(['http'], '$proxy'); my $req = new HTTP::Request GET => '$contentget'; my $res = $ua->request($req); if ($res->is_success) { $content= $res->content; } else { die "Could not get content"; }
Result is:
Could not get content at C:\CC\BUY\ptest.pl line 22.
There is also the
$ua->proxy( 'http', $subproxy );my $content = get( $contentget )
But that doesnt work either. Any help would be appreciated.
POST UPDATE 1
------------------------------------------------------------------
Thank you for responding afoken
but when i tried adding the modifcations i get the following error. I tried escaping the / problem but still cant get it to work.
use LWP::Simple; use LWP::Simple qw( $ua get ); use LWP::UserAgent; use HTTP::Request::Common qw(POST); use HTTP::Request my $ua = new LWP::UserAgent; $proxy='http://72.43.50.184:80/'; $contentget = "http://search.cpan.org/~gaas/libwww-perl-5.837/lib/LWP/ +UserAgent.pm"; $ua->timeout(3); $ua->proxy(['http'], $proxy); my $req = new HTTP::Request GET => '$contentget'; my $res = $ua->request($req); if ($res->is_success) { $content= $res->content; } else { die "Could not get content"; } # ptest.pl
C:\CC\BUY>ptest.pl Backslash found where operator expected at C:\CC\BUY\ptest.pl line 30, + near "CC\" Backslash found where operator expected at C:\CC\BUY\ptest.pl line 30, + near "BUY\" syntax error at C:\CC\BUY\ptest.pl line 30, near "Could not " Execution of C:\CC\BUY\ptest.pl aborted due to compilation errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LWP proxy setup difficulty
by afoken (Chancellor) on Oct 18, 2010 at 15:24 UTC | |
|
Re: LWP proxy setup difficulty
by Khen1950fx (Canon) on Oct 18, 2010 at 21:54 UTC | |
|
Re: LWP proxy setup difficulty
by Monkomatic (Sexton) on Oct 18, 2010 at 15:55 UTC |