Home: Perl Programming Help: Advanced:
monitor url with the help of proxy in perl. below code is not working plzzz corect it.



amurarka
Novice

Nov 13, 2011, 11:55 PM


Views: 22500
monitor url with the help of proxy in perl. below code is not working plzzz corect it.

pls tell me how to monitor url with the help of proxy in perl.
below code is not working plzzz corect it.

use warnings;
use strict;
use LWP::Simple qw($ua get);
$ua->proxy('http','acpwinggn2isa01a.aircel.co.in:80');
my $url = "http://google.com/";
my $webpage = get $url;

#my $url = get 'http://www.google.com/';

if (!$webpage) {

#open OUTPUT, ">>output.txt";
print "ERROR: Could not retrieve $url" ;
print scalar localtime(),"\n";
#close OUTPUT;

}
else {
#open OUTPUT, ">>output.txt";
print "no errors found ";
print scalar localtime(),"\n";
#close OUTPUT;

}

exit(0);
Frown


wickedxter
User

Nov 14, 2011, 10:00 AM


Views: 22409
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

why not use LWP::UserAgent its self rather then exporting the $ua variable from anouther (wrapper)module?


also you can remove the exit(0); for just 1;


(This post was edited by wickedxter on Nov 14, 2011, 10:01 AM)


amurarka
Novice

Nov 14, 2011, 8:17 PM


Views: 22315
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

can you plz tell there only. i didnt get it ............

i am new to perl,


wickedxter
User

Nov 15, 2011, 3:57 AM


Views: 22298
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

http://search.cpan.org/~gaas/libwww-perl-6.03/lib/LWP/UserAgent.pm

it has the examples to use the proxy its not much different then Simple but you get rid of the wrapper module Simple for direct access to the functions...





change the last line of the script to 1; rather then exit(0); if your going to use an End Of File.


amurarka
Novice

Nov 15, 2011, 4:55 AM


Views: 22295
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

can you plz do the changes in the script only how should i use it ..............



Thanks and Regards
amurarka


amurarka
Novice

Nov 15, 2011, 5:04 AM


Views: 22292
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

and also we are not able to locate new object.its showing error


wickedxter
User

Nov 15, 2011, 5:52 PM


Views: 22229
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

http://www.xav.com/perl/site/lib/lwpcook.html it has a proxy section


amurarka
Novice

Nov 15, 2011, 7:52 PM


Views: 22205
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

not geitng noothing is wokring.

could u write corect code plz here ?


amurarka
Novice

Nov 15, 2011, 9:23 PM


Views: 22188
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

#!/usr/bin/perl
use strict;
use warnings;
require LWP::useragent;
use HTTP::Request::Common;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->proxy(['http', 'ftp'] => 'http://acpwinggn2isa02.aircel.co.in');
my $req = HTTP::Request->new('GET',"http://www.aircel.com");
my $res = $ua->request($req);


if ($res->is_success)
{
print " retrieve $req" ;
}
else {
print "errors found ";
};


wickedxter
User

Nov 16, 2011, 2:14 PM


Views: 22139
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.


Code
 
use strict;
use warnings;
use LWP::UserAgent;


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

#set proxy ip address and port
$ua->proxy(['http'] => 'http://87.106.143.132:3128');

#send request threw proxy for website
my $req = $ua->get("http://www.google.com");


#check if success and print
if ($req->is_success){
print $req->decoded_content;
} else {
print "errors found ";
};


good luck


amurarka
Novice

Nov 16, 2011, 8:21 PM


Views: 22112
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

not working ..........

only else part is showing in both the conditons

errors found.
if not wrking


wickedxter
User

Nov 17, 2011, 2:48 AM


Views: 22104
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

what ver of perl u using? it worked for me on 5.14.2

are you useing this is a web broswer? if so you'll need to add this line

Code
print "content-type: text/html\n\n";



some where at the top of the script. also if you've changed the code plz post again so i can see your changes.


(This post was edited by wickedxter on Nov 17, 2011, 2:54 AM)


amurarka
Novice

Nov 17, 2011, 3:04 AM


Views: 22099
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

active perl 5.12 i am using
no i didid nt do any changes


wickedxter
User

Nov 17, 2011, 4:17 AM


Views: 22093
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

Do you have a test webserver or are you running from console?


amurarka
Novice

Nov 17, 2011, 7:49 PM


Views: 22030
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

i am running on 32 bit server through command prompt


wickedxter
User

Nov 18, 2011, 12:43 PM


Views: 21958
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it.

maybe the proxy ip address is restricted find one thats USA based and try it.. b/c it works for me in the command promt displays all sites source code...