Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: create a HTTP::Response object from a raw buffer?

by pg (Canon)
on Mar 30, 2003 at 18:13 UTC ( [id://246759]=note: print w/replies, xml ) Need Help??


in reply to create a HTTP::Response object from a raw buffer?

Depends on the nature of your application, you may want to consider mod_perl. LWP::UserAgent requires a new thread/process for each session in a multi-user environment. If your site is "hot", and may get many hits within a minute, LWP::UserAgent is absolutely not a choice.

Anyway, the following piece of code receives the response, and parse the header into a hash.
use IO::Socket::INET; use Data::Dumper; use strict; my $s = new IO::Socket::INET(Proto => "tcp", PeerAddr => "www.yahoo.com", PeerPort => 80) || die "failed to new socket\n"; print $s "GET http://www.yahoo.com HTTP/1.1\r\nHost: www.yahoo.com\r\n +\r\n"; my $response; while (<$s>) { chomp; if (m/^\s*$/) {last}; m/(.*?)[:| ]\s*(.*?)[\r|\n]/; $response->{$1} = $2; } close($s); print Dumper($response);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246759]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-25 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found