… | |
… | |
59 | Executes an HTTP-HEAD request. See the http_request function for details on |
59 | Executes an HTTP-HEAD request. See the http_request function for details on |
60 | additional parameters. |
60 | additional parameters. |
61 | |
61 | |
62 | =item http_post $url, $body, key => value..., $cb->($data, $headers) |
62 | =item http_post $url, $body, key => value..., $cb->($data, $headers) |
63 | |
63 | |
64 | Executes an HTTP-POST request with a requets body of C<$bod>. See the |
64 | Executes an HTTP-POST request with a request body of C<$bod>. See the |
65 | http_request function for details on additional parameters. |
65 | http_request function for details on additional parameters. |
66 | |
66 | |
67 | =item http_request $method => $url, key => value..., $cb->($data, $headers) |
67 | =item http_request $method => $url, key => value..., $cb->($data, $headers) |
68 | |
68 | |
69 | Executes a HTTP request of type C<$method> (e.g. C<GET>, C<POST>). The URL |
69 | Executes a HTTP request of type C<$method> (e.g. C<GET>, C<POST>). The URL |
… | |
… | |
71 | |
71 | |
72 | The callback will be called with the response data as first argument |
72 | The callback will be called with the response data as first argument |
73 | (or C<undef> if it wasn't available due to errors), and a hash-ref with |
73 | (or C<undef> if it wasn't available due to errors), and a hash-ref with |
74 | response headers as second argument. |
74 | response headers as second argument. |
75 | |
75 | |
76 | All the headers in that has are lowercased. In addition to the response |
76 | All the headers in that hash are lowercased. In addition to the response |
77 | headers, the three "pseudo-headers" C<HTTPVersion>, C<Status> and |
77 | headers, the three "pseudo-headers" C<HTTPVersion>, C<Status> and |
78 | C<Reason> contain the three parts of the HTTP Status-Line of the same |
78 | C<Reason> contain the three parts of the HTTP Status-Line of the same |
79 | name. |
79 | name. |
80 | |
80 | |
81 | If an internal error occurs, such as not being able to resolve a hostname, |
81 | If an internal error occurs, such as not being able to resolve a hostname, |
82 | then C<$data> will be C<undef>, C<< $headers->{Status} >> will be C<599> |
82 | then C<$data> will be C<undef>, C<< $headers->{Status} >> will be C<599> |
83 | and the C<Reason> pseudo-header will contain an error message. |
83 | and the C<Reason> pseudo-header will contain an error message. |
|
|
84 | |
|
|
85 | A typical callback might look like this: |
|
|
86 | |
|
|
87 | sub { |
|
|
88 | my ($body, $hdr) = @_; |
|
|
89 | |
|
|
90 | if ($hdr->{Status} =~ /^2/) { |
|
|
91 | ... everything should be ok |
|
|
92 | } else { |
|
|
93 | print "error, $hdr->{Status} $hdr->{Reason}\n"; |
|
|
94 | } |
|
|
95 | } |
84 | |
96 | |
85 | Additional parameters are key-value pairs, and are fully optional. They |
97 | Additional parameters are key-value pairs, and are fully optional. They |
86 | include: |
98 | include: |
87 | |
99 | |
88 | =over 4 |
100 | =over 4 |