spaz has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use IO::Socket; use strict; my $socket = &new_socket( { host => "foo.com", port => 80 } ); print $socket &new_post( { data => "foobar", path => "/cgi-bin/foobar.pl", host => "http://www.foo.com", referer => "http://www.foo.com/baz.html" } ); print OUT while( <$socket> ); ######################################### sub new_socket { my( $args ) = @_; return IO::Socket::INET->new( PeerAddr => $$args{host}, PeerPort => $$args{port}, Proto => "tcp", Type => SOCK_STREAM ); } sub new_post { my( $args ) = @_; my $length = length( $$args{data} ); my $post = "POST $$args{path} HTTP/1.0\n"; $post .= "Host: $$args{host}\n"; $post .= "Accept: text/html, text/plain, text/richtext"; $post .= ", text/enriched\n"; $post .= "Accept-Encoding: gzip, compress\n"; $post .= "Accept-Language: en\n"; $post .= "Pragma: no-cache\n"; $post .= "Cache-Control: no-cache\n"; $post .= "User-Agent: Lynx/2.8.3dev.18 libwww-FM/2.14\n"; $post .= "Referer: $$args{referer}\n"; $post .= "Content-type: application/x-www-form-urlencoded\n"; $post .= "Content-length: $length\n\n"; $post .= "$$args{data}\n"; return $post; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Did I have to roll my own?
by c-era (Curate) on Jan 19, 2001 at 01:02 UTC | |
by merlyn (Sage) on Jan 19, 2001 at 02:23 UTC |