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: 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

Post #1 of 16 (15063 views)
monitor url with the help of proxy in perl. below code is not working plzzz corect it. Can't Post

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

Post #2 of 16 (14972 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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

Post #3 of 16 (14878 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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

i am new to perl,


wickedxter
User

Nov 15, 2011, 3:57 AM

Post #4 of 16 (14861 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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

Post #5 of 16 (14858 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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

Post #6 of 16 (14855 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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


wickedxter
User

Nov 15, 2011, 5:52 PM

Post #7 of 16 (14792 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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


amurarka
Novice

Nov 15, 2011, 7:52 PM

Post #8 of 16 (14768 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

not geitng noothing is wokring.

could u write corect code plz here ?


amurarka
Novice

Nov 15, 2011, 9:23 PM

Post #9 of 16 (14751 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

#!/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

Post #10 of 16 (14702 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post


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

Post #11 of 16 (14675 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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

only else part is showing in both the conditons

errors found.
if not wrking


wickedxter
User

Nov 17, 2011, 2:48 AM

Post #12 of 16 (14667 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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

Post #13 of 16 (14662 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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


wickedxter
User

Nov 17, 2011, 4:17 AM

Post #14 of 16 (14656 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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


amurarka
Novice

Nov 17, 2011, 7:49 PM

Post #15 of 16 (14593 views)
Re: [wickedxter] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

i am running on 32 bit server through command prompt


wickedxter
User

Nov 18, 2011, 12:43 PM

Post #16 of 16 (14521 views)
Re: [amurarka] monitor url with the help of proxy in perl. below code is not working plzzz corect it. [In reply to] Can't Post

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...

 
 


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

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