get page with IO::Socket , but having trouble saving to file

2002-07-13 Thread FLAHERTY, JIM-CONT

Hello, get page with IO::Socket , but having trouble saving to file

This is what I got:


use IO::Socket;

  $host = "www.cnn.com";

  $document = "/newhomepage1.htm";

 foreach $doc ($document) {

$remote = IO::Socket::INET->new( Proto => "tcp",
 PeerAddr  => $host,
 PeerPort  => "http(80)",
);

 }


$EOL = "\015\012";

$BLANK = $EOL x 2;




unless ($remote) { die "cannot connect to http daemon on $host" }

$remote->autoflush(1);

#print $remote "GET $document HTTP/1.0" . $BLANK;



  open(LOG9,">>/var/www/html/bad/bali.txt");

   print LOG9 " $remote \"GET $document HTTP/1.0\" . $BLANK";




 while ( <$remote> ) { print LOG9 }

close $remote;
close(LOG9);







Help , what am I doing Wrong ??

Jim

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




Re: get page with IO::Socket , but having trouble saving to file

2002-07-13 Thread Felix Geerinckx

on Sat, 13 Jul 2002 15:06:38 GMT, Jim-Cont Flaherty wrote:

> Hello, get page with IO::Socket , but having trouble saving to file
> 
> This is what I got:

> [code snipped]

> Help , what am I doing Wrong ??

You are trying to reinvent the wheel instead of using LWP::Simple.

perldoc LWP::Simple

-- 
felix

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




Re: get page with IO::Socket , but having trouble saving to file

2002-07-13 Thread drieux


On Saturday, July 13, 2002, at 08:06 , FLAHERTY, JIM-CONT wrote:
[..]
> unless ($remote) { die "cannot connect to http daemon on $host" }
>
> $remote->autoflush(1);
[..]
>print LOG9 " $remote \"GET $document HTTP/1.0\" . $BLANK";
>
>  while ( <$remote> ) { print LOG9 }
[..]

p0: way too much work in the long run, you clearly want
to become friends with

use LWP::UserAgent;
use HTTP::Request;

p1: we've all tried variations on this mine just used Sockets

http://www.wetware.com/drieux/pbl/perlTrick/subStuff/SimpleLib/WebAccess.txt

my $msg = "GET $dtk_url HTTP/1.1\nHost: $dtk_host:$dtk_port\n\n";

print $dtk_sock $msg;

what you technically missed in the HTTP spect is
the second line that is required

p2: I have been playing around with some simple demonstrations of
how to bollock up the mess -

http://www.wetware.com/drieux/pbl/perlTrick/CBO/jobBot/p1b.txt

  sub get_web_page {
 my ($the_url , $parser, $method, $msg) = @_;

 $method ||= 'GET'; # so that we have a default here

 my $return_string =  "Your Request Failed\n";

 my $ua = LWP::UserAgent->new;
 my $req = HTTP::Request->new($method => $the_url );
 if ($msg && $method eq 'POST') {
 $req->header('Content-type', 'application/x-www-form-urlencoded');
 $req->content($msg);
 }
 my $res = $ua->request($req);
 if ($res->is_success) {
 #
 # since we know that we want to have parsers passed in
 # as a rule of thumb - why not just, well, have this fixed
 #
 $return_string = ($parser)? $parser->($res): $res->content;
 } else {
 $return_string .= $res->error_as_HTML if ($res->is_error);
 }
 return($return_string);
  } # end of get_web_page


HTH

ciao
drieux

---


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