CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
perl proxy http lwp::simple & lwp::useragent

 



Jmp
New User

Dec 24, 2014, 9:16 AM

Post #1 of 2 (4020 views)
perl proxy http lwp::simple & lwp::useragent Can't Post

Hi,

How do I use a proxy?
I tried all the commented-out methods, and each returns the same mistake?


Code
Useless use of addition (+) in void context at ./a.pl line 35. 
Can't connect to 118.97.130.10:8080 (timeout)

LWP::Protocol::http::Socket: connect: timeout at /usr/share/perl5/LWP/Protocol/http.pm line 41.



Code
#!/usr/bin/perl 
use warnings;
use LWP::UserAgent;
use LWP::Simple;

# 118.97.130.10:8080
# proxy type HTTP

#$ua->env_proxy();
#$ENV{HTTP_PROXY} = 'http://118.97.130.10:8080';

my $ua = LWP::UserAgent->new;

#my %proxy = ( host => 'http://118.97.130.10:8080' );
#use LWP::Simple qw(mirror RC_OK RC_NOT_MODIFIED $ua);
#$ua->proxy(http => "$proxy{host}") if (defined $proxy{host});


$ua->agent('Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1');
$ua->timeout(15);
#$ua->proxy('http','http://118.97.130.10:8080');
#$ua->proxy(['http'] => 'http://118.97.130.10:8080');
$ua->timeout(15);

$res = $ua->get('http://www.google.com/search?q=perl'); #&start=10
my @msg = $res->content;
print @msg;
print "\n";



Zhris
Enthusiast

Dec 24, 2014, 10:15 AM

Post #2 of 2 (4012 views)
Re: [Jmp] perl proxy http lwp::simple & lwp::useragent [In reply to] Can't Post

Hi,

Your code looks ok to me, specifically the $ua->proxy method you tried.

I can't see why you are receiving a "Useless use of addition (+) in void context" warning either, perhaps you ran a different version of your code?

I see that it is being reported that your request is timing out, it is taking too long to process your request and erroring fifteen seconds as per your defined timeout. Is your proxy a dud?

I tested a similar code using a different proxy and url without issue.

http://demo.massweb.co.uk/lwp/proxy.pl

Code
#! /usr/bin/perl 
use strict;
use warnings;
use LWP::UserAgent;

use CGI::Carp qw/fatalsToBrowser/; # remove if not in web environment.
print "content-type: text/plain\n\n"; # remove if not in web environment.

my $ua = LWP::UserAgent->new;

$ua->agent( 'Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20100101 Firefox/14.0.1' );
$ua->timeout( 10 );
$ua->proxy( 'https', 'https://static-209-170-151-14.alwaysdedicated.net' );

my $response = $ua->get( 'http://demo.massweb.co.uk/index.pl' ); # 'http://www.google.com/search?q=perl'

if ( $response->is_success )
{
print $response->decoded_content;
}
else
{
die $response->status_line;
}


Regards,

Chris


(This post was edited by Zhris on Dec 24, 2014, 10:20 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives