windows - Sending HTTP request in Perl -
how can send request in perl on windows?
get /index.html http/1.1 host: www.example.org cookie: test=quest
you can using sockets:
use io::socket; $sock = new io::socket::inet ( peeraddr => 'www.example.org', peerport => '80', proto => 'tcp', ); die "could not create socket: $!\n" unless $sock; print $sock "get /index.html http/1.0\r\n"; print $sock "host: www.example.org\r\n"; print $sock "cookie: test=quest\r\n\r\n"; print while <$sock>; close($sock);
but might want consider using lwp (libwww-perl) instead:
use lwp::useragent; $ua = lwp::useragent->new; $req = http::request->new(get => 'http://www.example.org/index.html'); $req->header('cookie' => 'test=quest'); # send request $res = $ua->request($req); # check outcome if ($res->is_success) { print $res->decoded_content } else { print "error: " . $res->status_line . "\n" }
you might try reading lwp cookbook introduction lwp.
Comments
Post a Comment