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:
help with IO::Sockets.

 



arpith
Deleted

Sep 15, 2000, 10:32 PM

Post #1 of 5 (1799 views)
help with IO::Sockets. Can't Post

 
Hello folks,

I'm having some problems with IO::Sockets. I'm trying to read webpages on the internet, and the code seems to be failing on one particular page: http://www.bigo.com/B/B2/B2A05.html
It just doesn't seem to be able to read the page. Why?

The site works fine from my browser, but not with this code... Any ideas why? I'm clueless :-(

Thanks for all help!
Arpith


<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

$|++;

BEGIN {
use CGI::Carp qw(fatalsToBrowser);
}

use CGI;
$q = new CGI;

$link = $q->param('link');

unless ($link) {
$link = "http://www.yahoo.com/";
}

print "Content-type:text/html\n\n";
print "<h2>Link: $link</h2><br><br>";

$a = &validate_url($link);
print $a;
exit;


sub validate_url {

my $url = $_[0];

$url =~ m/http:\/\/(.*)/i;
$temp = $1;
unless ($temp =~ m/\//s) {
$url .= "/";
}

use IO::Socket;
$method = "GET";
$url =~ m/http:\/\/([\w\.-]*)\/(.*)/i;
$host = $1;
$path = "/$2";

undef $socket;
$socket = new IO::Socket::INET( PeerAddr => $host,
PeerPort => 80,
Proto => 'tcp',
Timeout => 2,
Type => SOCK_STREAM, ) or return "error";
print $socket "$method $path HTTP/1.0\n";
print $socket "User-Agent: $default_user_agent_io_socket\n\n";
$ct = "";
while (<$socket> ) {
$ct .= $_;
}
close ($socket);

return $ct;
}
</pre><HR></BLOCKQUOTE>


KaoAtlantis
Novice

Sep 17, 2000, 9:44 PM

Post #2 of 5 (1799 views)
Re: help with IO::Sockets. [In reply to] Can't Post

I am not sure if you use IE5.5, But That page is giving me the Connection Refused error...

Maybe that is why it wont read it...

-Kao Atlantis


arpith
Deleted

Sep 18, 2000, 1:52 AM

Post #3 of 5 (1799 views)
Re: help with IO::Sockets. [In reply to] Can't Post

 
Hello,

Actually, when I posted this thread the site was working fine! Its only now that this error has cropped up :-(

Check out the cache at google: http://www.google.com/search?q=cache:www2.bigo.com/bigo/B/B2/B2A05.html+&hl=en

On the perl-win32-web mailing list, they said it might be a problem of the server; ie: the site was hosted on a Mac. So, I modified these lines in the code:
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


print $socket "$method $path HTTP/1.0\n"; print $socket "User-Agent: $default_user_agent_io_socket\n\n";
</pre><HR></BLOCKQUOTE>

TO

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


print $socket "$method $path HTTP/1.0\r\n"; print $socket "User-Agent: $default_user_agent_io_socket\r\n\r\n";
</pre><HR></BLOCKQUOTE>


i.e: I added a \r
That gave some response from the server, but still gave me an error:

HTTP/1.0 200 OK Content-type: text/html Content-Length: 69 Error: template
'rejobi_main:rejobi_server:B:B2:B2A05.html' not found


I have no idea what the problem is!

I was wondering if any one of you know some site hosted on a Mac, so I can test it on that?

Thanks
Arpith




arpith
Deleted

Sep 18, 2000, 9:27 AM

Post #4 of 5 (1799 views)
Re: help with IO::Sockets. [In reply to] Can't Post

 http://www.bigo.com/B/B2/B2A05.html
Well, the site should work now... Its up again I think..

Arpith


perlkid
stranger

Sep 18, 2000, 10:41 AM

Post #5 of 5 (1799 views)
Re: help with IO::Sockets. [In reply to] Can't Post

 
I'm on 5.5 too and I get page cannot be displayed.

I really think your code is fine, I use sockets too.

perlkid

 
 


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

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