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.
In reply to LWP proxy setup difficulty by Monkomatic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |