| 1 |
joko |
1.1 |
#use HTTP::Request; |
| 2 |
|
|
use HTTP::Request::Common qw(GET POST); |
| 3 |
|
|
sub POE::Kernel::ASSERT_DEFAULT () { 1 } |
| 4 |
|
|
use POE qw(Component::Client::HTTP); |
| 5 |
|
|
|
| 6 |
|
|
sub DEBUG () { 0 } |
| 7 |
|
|
|
| 8 |
|
|
|
| 9 |
|
|
POE::Component::Client::HTTP->spawn( |
| 10 |
|
|
Agent => 'SpiffCrawler/0.90', # defaults to something long |
| 11 |
|
|
Alias => 'ua', # defaults to 'weeble' |
| 12 |
|
|
From => 'spiffster@perl.org', # defaults to undef (no header) |
| 13 |
|
|
Protocol => 'HTTP/0.9', # defaults to 'HTTP/1.0' |
| 14 |
|
|
Timeout => 60, # defaults to 180 seconds |
| 15 |
|
|
); |
| 16 |
|
|
|
| 17 |
|
|
# a http-request |
| 18 |
|
|
my $request = HTTP::Request->new(GET => 'http://www.ilo.de/'); |
| 19 |
|
|
# post request to POE-Kernel |
| 20 |
|
|
$poe_kernel->post( 'ua', # posts to the 'ua' alias |
| 21 |
|
|
'request', # posts to ua's 'request' state |
| 22 |
|
|
'response_handler', # which of our states will receive the response |
| 23 |
|
|
$request, # an HTTP::Request object |
| 24 |
|
|
); |
| 25 |
|
|
|
| 26 |
|
|
# This is the sub which is called when the session receives a |
| 27 |
|
|
# 'response' event. |
| 28 |
|
|
sub response_handler { |
| 29 |
|
|
my ($request_packet, $response_packet) = @_[ARG0, ARG1]; |
| 30 |
|
|
my $request_object = $request_packet->[0]; # HTTP::Request |
| 31 |
|
|
my $response_object = $response_packet->[0]; # HTTP::Response |
| 32 |
|
|
|
| 33 |
|
|
print "*" x 78, "\n"; |
| 34 |
|
|
print "*** my request:\n"; |
| 35 |
|
|
print "-" x 78, "\n"; |
| 36 |
|
|
print $request_object->as_string(); |
| 37 |
|
|
print "*" x 78, "\n"; |
| 38 |
|
|
|
| 39 |
|
|
print "*" x 78, "\n"; |
| 40 |
|
|
print "*** their response:\n"; |
| 41 |
|
|
print "-" x 78, "\n"; |
| 42 |
|
|
print $response_object->as_string(); |
| 43 |
|
|
print "*" x 78, "\n"; |
| 44 |
|
|
} |
| 45 |
|
|
|
| 46 |
|
|
$poe_kernel->run(); |