ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-HTTP/README
(Generate patch)

Comparing AnyEvent-HTTP/README (file contents):
Revision 1.2 by root, Thu Jun 5 18:42:16 2008 UTC vs.
Revision 1.6 by root, Fri Oct 24 01:27:29 2008 UTC

1NAME 1NAME
2 AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client 2 AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client
3 3
4SYNOPSIS 4SYNOPSIS
5 use AnyEvent::HTTP; 5 use AnyEvent::HTTP;
6
7 http_get "http://www.nethype.de/", sub { print $_[1] };
8
9 # ... do something else here
6 10
7DESCRIPTION 11DESCRIPTION
8 This module is an AnyEvent user, you need to make sure that you use and 12 This module is an AnyEvent user, you need to make sure that you use and
9 run a supported event loop. 13 run a supported event loop.
10 14
24 limited support. 28 limited support.
25 29
26 METHODS 30 METHODS
27 http_get $url, key => value..., $cb->($data, $headers) 31 http_get $url, key => value..., $cb->($data, $headers)
28 Executes an HTTP-GET request. See the http_request function for 32 Executes an HTTP-GET request. See the http_request function for
29 details on additional parameters. 33 details on additional parameters and the return value.
30 34
31 http_head $url, key => value..., $cb->($data, $headers) 35 http_head $url, key => value..., $cb->($data, $headers)
32 Executes an HTTP-HEAD request. See the http_request function for 36 Executes an HTTP-HEAD request. See the http_request function for
33 details on additional parameters. 37 details on additional parameters and the return value.
34 38
35 http_post $url, $body, key => value..., $cb->($data, $headers) 39 http_post $url, $body, key => value..., $cb->($data, $headers)
36 Executes an HTTP-POST request with a request body of $bod. See the 40 Executes an HTTP-POST request with a request body of $body. See the
37 http_request function for details on additional parameters. 41 http_request function for details on additional parameters and the
42 return value.
38 43
39 http_request $method => $url, key => value..., $cb->($data, $headers) 44 http_request $method => $url, key => value..., $cb->($data, $headers)
40 Executes a HTTP request of type $method (e.g. "GET", "POST"). The 45 Executes a HTTP request of type $method (e.g. "GET", "POST"). The
41 URL must be an absolute http or https URL. 46 URL must be an absolute http or https URL.
47
48 When called in void context, nothing is returned. In other contexts,
49 "http_request" returns a "cancellation guard" - you have to keep the
50 object at least alive until the callback get called. If the object
51 gets destroyed before the callbakc is called, the request will be
52 cancelled.
42 53
43 The callback will be called with the response data as first argument 54 The callback will be called with the response data as first argument
44 (or "undef" if it wasn't available due to errors), and a hash-ref 55 (or "undef" if it wasn't available due to errors), and a hash-ref
45 with response headers as second argument. 56 with response headers as second argument.
46 57
47 All the headers in that hash are lowercased. In addition to the 58 All the headers in that hash are lowercased. In addition to the
48 response headers, the three "pseudo-headers" "HTTPVersion", "Status" 59 response headers, the "pseudo-headers" "HTTPVersion", "Status" and
49 and "Reason" contain the three parts of the HTTP Status-Line of the 60 "Reason" contain the three parts of the HTTP Status-Line of the same
61 name. The pseudo-header "URL" contains the original URL (which can
62 differ from the requested URL when following redirects).
63
50 same name. If the server sends a header multiple lines, then their 64 If the server sends a header multiple times, then their contents
51 contents will be joined together with "\x00". 65 will be joined together with a comma (","), as per the HTTP spec.
52 66
53 If an internal error occurs, such as not being able to resolve a 67 If an internal error occurs, such as not being able to resolve a
54 hostname, then $data will be "undef", "$headers->{Status}" will be 68 hostname, then $data will be "undef", "$headers->{Status}" will be
55 599 and the "Reason" pseudo-header will contain an error message. 69 599 and the "Reason" pseudo-header will contain an error message.
56 70
131 use Data::Dumper; 145 use Data::Dumper;
132 print Dumper $hdr; 146 print Dumper $hdr;
133 } 147 }
134 ; 148 ;
135 149
150 Example: make another simple HTTP GET request, but immediately try
151 to cancel it.
152
153 my $request = http_request GET => "http://www.nethype.de/", sub {
154 my ($body, $hdr) = @_;
155 print "$body\n";
156 };
157
158 undef $request;
159
136 GLOBAL FUNCTIONS AND VARIABLES 160 GLOBAL FUNCTIONS AND VARIABLES
137 AnyEvent::HTTP::set_proxy "proxy-url" 161 AnyEvent::HTTP::set_proxy "proxy-url"
138 Sets the default proxy server to use. The proxy-url must begin with 162 Sets the default proxy server to use. The proxy-url must begin with
139 a string of the form "http://host:port" (optionally "https:..."). 163 a string of the form "http://host:port" (optionally "https:...").
140 164
166 190
167SEE ALSO 191SEE ALSO
168 AnyEvent. 192 AnyEvent.
169 193
170AUTHOR 194AUTHOR
171 Marc Lehmann <schmorp@schmorp.de> 195 Marc Lehmann <schmorp@schmorp.de>
172 http://home.schmorp.de/ 196 http://home.schmorp.de/
173 197

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines