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: Intermediate:
Socket function !

 



wisgroups
Novice

Sep 26, 2002, 7:42 AM

Post #1 of 5 (974 views)
Socket function ! Can't Post

Hello,

I am using socket and connect function of perl on my cgi script to fetch documents.
My script works well on my local server but not on my site hosted on the Net.
It returns No route to host error and I can't understand why.
Please help me.

Here is my perl script:


Code
#!/usr/local/bin/perl 

print "Content-Type:text/html\n\n";

$url="www.dmoz.org";

print getUrl($url,"Mozilla/4.0");

sub getUrl {

my($URL, $Agent, $Referer) = @_;
my($hostname, $document) = split (/\//, $URL, 2);
$document = "/" . $document;
$Agent = $ENV{'HTTP_USER_AGENT'} if ($Agent eq "");
$Referer = $ENV{'HTTP_REFERER'} if ($Referer eq "");

my($name, $aliases, $type, $len, $addr) = gethostbyname($hostname);
socket (CGI, 2, 1, 0);
my($socketaddr) = pack ('S n a4 x8', 2, 80, $addr);
connect (CGI, $socketaddr) or print "Error: $!";

$| = 1;
my($old) = select(CGI);
$| = 1;
select($old);

print CGI "GET $document HTTP/1.0\n";
print CGI "Host: $hostname\n";
print CGI "Accept: */*\n";
print CGI "Connection: Keep-Alive\n";
print CGI "Accept_Language: $ENV{'HTTP_ACCEPT_LANGUAGE'}\n";
print CGI "User-Agent: $Agent\n";
print CGI "Referer: $Referer\n";
print CGI "\n";

while (read (CGI, $in, 1024) == 1024) {
$NewPage .= $in;
}
$NewPage .= $in;

close(CGI);

return $NewPage;

}



fashimpaur
User / Moderator

Sep 26, 2002, 8:23 AM

Post #2 of 5 (971 views)
Re: [wisgroups] Socket function ! [In reply to] Can't Post

wisgroups:

You are duplicating a lot of effort that went into creating solid code.

Try using LWP::UserAgent and HTTP::Request Modules.

These should fix your problems.

Good Luck,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


Paul
Enthusiast

Sep 26, 2002, 10:15 AM

Post #3 of 5 (968 views)
Re: [fashimpaur] Socket function ! [In reply to] Can't Post

...or LWP::Simple.


wisgroups
Novice

Sep 27, 2002, 2:15 AM

Post #4 of 5 (961 views)
Re: [RedRum] Socket function ! [In reply to] Can't Post

I know LWP and HTTP::Request modeules can do this in an easy way, but these modules aren't installed on my server so I should use another function or module.
I decided to do this work with socket and connect function of perl. Everything appears to be O.K in my local server but not in web site hosted on the Net.
It returns No route to host error and I can't understand why. Please help me so that I can resolve that problem.


thebitch
User

Sep 27, 2002, 4:23 AM

Post #5 of 5 (960 views)
Re: [wisgroups] Socket function ! [In reply to] Can't Post

No route to host
Ought to give you a clue.

You cannot get what you didn't pay for,
and your host obviously doesn't allow you to do that kind of stuff

You wish to resolve your issue, you must talk to whoever
is providing you with hosting

 
 


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

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