
liles
Deleted
Feb 16, 2000, 10:36 PM
Post #1 of 1
(4619 views)
|
IO::Socket Programming
|
Can't Post
|
|
Hello: I am trying to write a Perl script that will send HTTP requests to a WEB server and read the server's response using a socket. I want to read the information to the socket from a flat file. I have been using the example on page 247 of O'Reilly's book "Learning Perl" (the webget client) as a guide. I have my own web server set up (Apache). The flat file I want to read, "test2" follows (it is a plain text file named "test2" in my current working directory): _____________________________________________ PUT /dav/dav/foo.html HTTP/1.1 HOST: liles.raleigh.ibm.com Content-Type: text/plain Content-Length: 25 This is so frustrating!! _____________________________________________ My perl script, "webget.pl", follows: ############################################# $host = shift(@ARGV); print "Host is $host\n"; foreach $document ( @ARGV) { $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => "http(80)", ); unless ($remote) {die "cannot connect to http deamon on $host"} $remote->autoflush(1); print "document = $document\n"; open(DOC, "$document") | | die "Sorry, I could not find $document\n"; while (@line = <DOC> ) { foreach $line (@line) { # print line that was just read print "line = $line\n"; # send line to socket print $remote $line; } } # See remote before while loop print "before while loop: remote = $remote\n"; # hangs in while loop while ( <$remote> ) {print} # see if I exit while loop print "after while remote\n"; close $remote; } ########################################### I invoke it as follows: perl webget.pl liles test2 where "liles" is the host server (Apache webserver) and "test2" is the document file I am reading. The problem I am having is that is hanging in the second "while" loop: (while ( <$remote> ) {print} I expect to see a file named "foo.html" created on my Web server with the line "This is so frustrating" in it. I am a total novice to Perl programming. Any help or suggestions would be appreciated. Susan Liles RTP, NC
|