"Andre Chaves Mascarenhas" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi
How do i read a web page with socks?
do i send?
if SK is a open socjet at port 80 at lets say www.yahoo.com if i send
print SK "GET /index.htm HTTP/1.1\n"
will i get the www.yahoo.com/index.htm page ?
Thanks

that's bascially about it. your request header doesn't seem to be a complete
HTTP request though. for demonstrating purpose, something like that should
work:

#!/usr/bin/perl -w
use strict;

use Socket;

socket(KDE,PF_INET,SOCK_STREAM,getprotobyname('tcp'));

my $internet_address = inet_aton('kde-look.org') || die $!;

connect(KDE,sockaddr_in(80,$internet_address)) || die $!;

select((select(KDE), $! = 1)[0]);

syswrite(KDE,"GET /index.htm HTTP/1.1\r\nHost: www.kde-look.org\r\n\r\n");

while(sysread(KDE,my $line,1024)){

 print "$line";
}

close(KDE);

__END__

the IO::Socket::INET module makes things a lot easier for you so other than
educational purpose there is no reason to play around with the low level
Socket api. the following bascially accomplish the same thing:

#!/usr/bin/perl -w
use strict;

use IO::Socket::INET;

my $s = IO::Socket::INET->new(PeerAddr => 'www.kde-look.org',
         PeerPort => 80,
         Proto => 'tcp',
         Type => SOCK_STREAM) || die $!;

print $s "GET /index.htm HTTP/1.1\r\nHost: www.kde-look.org\r\n\r\n";

print while(<$s>);

__END__

finally, if you are interested in downloading web page from the net,
LWP::UserAgent might worth a look:

#!/usr/bin/perl -w
use strict;

use LWP::UserAgent;

my $rs = LWP::UserAgent->new->request(HTTP::Request->new(GET =>
'http://www.kde-look.org'));

print $rs->content if($rs->is_success);

__END__

which again accomplish bascially the same thing as above. more info can be
found at:

perldoc -f socket
perldoc -f connect
perldoc -f sysread
perldoc -f syswrite
perldoc -f select

... and a bunch other socket releated functions. Or:

perldoc IO::Socket::INET
perldoc LWP::UserAgent
perldoc HTTP::Request
perldoc HTTP::Reponse

david



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to