… | |
… | |
12 | 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 |
13 | run a supported event loop. |
13 | run a supported event loop. |
14 | |
14 | |
15 | This module implements a simple, stateless and non-blocking HTTP client. |
15 | This module implements a simple, stateless and non-blocking HTTP client. |
16 | It supports GET, POST and other request methods, cookies and more, all |
16 | It supports GET, POST and other request methods, cookies and more, all |
17 | on a very low level. It can follow redirects supports proxies and |
17 | on a very low level. It can follow redirects, supports proxies, and |
18 | automatically limits the number of connections to the values specified |
18 | automatically limits the number of connections to the values specified |
19 | in the RFC. |
19 | in the RFC. |
20 | |
20 | |
21 | It should generally be a "good client" that is enough for most HTTP |
21 | It should generally be a "good client" that is enough for most HTTP |
22 | tasks. Simple tasks should be simple, but complex tasks should still be |
22 | tasks. Simple tasks should be simple, but complex tasks should still be |
… | |
… | |
121 | You really should provide your own "User-Agent:" header value |
121 | You really should provide your own "User-Agent:" header value |
122 | that is appropriate for your program - I wouldn't be surprised |
122 | that is appropriate for your program - I wouldn't be surprised |
123 | if the default AnyEvent string gets blocked by webservers sooner |
123 | if the default AnyEvent string gets blocked by webservers sooner |
124 | or later. |
124 | or later. |
125 | |
125 | |
|
|
126 | Also, make sure that your headers names and values do not |
|
|
127 | contain any embedded newlines. |
|
|
128 | |
126 | timeout => $seconds |
129 | timeout => $seconds |
127 | The time-out to use for various stages - each connect attempt |
130 | The time-out to use for various stages - each connect attempt |
128 | will reset the timeout, as will read or write activity, i.e. |
131 | will reset the timeout, as will read or write activity, i.e. |
129 | this is not an overall timeout. |
132 | this is not an overall timeout. |
130 | |
133 | |
131 | Default timeout is 5 minutes. |
134 | Default timeout is 5 minutes. |
132 | |
135 | |
133 | proxy => [$host, $port[, $scheme]] or undef |
136 | proxy => [$host, $port[, $scheme]] or undef |
134 | Use the given http proxy for all requests. If not specified, |
137 | Use the given http proxy for all requests, or no proxy if |
135 | then the default proxy (as specified by $ENV{http_proxy}) is |
|
|
136 | used. |
138 | "undef" is used. |
137 | |
139 | |
138 | $scheme must be either missing or must be "http" for HTTP. |
140 | $scheme must be either missing or must be "http" for HTTP. |
|
|
141 | |
|
|
142 | If not specified, then the default proxy is used (see |
|
|
143 | "AnyEvent::HTTP::set_proxy"). |
139 | |
144 | |
140 | body => $string |
145 | body => $string |
141 | The request body, usually empty. Will be sent as-is (future |
146 | The request body, usually empty. Will be sent as-is (future |
142 | versions of this module might offer more options). |
147 | versions of this module might offer more options). |
143 | |
148 | |
… | |
… | |
365 | AnyEvent::HTTP::set_proxy "proxy-url" |
370 | AnyEvent::HTTP::set_proxy "proxy-url" |
366 | Sets the default proxy server to use. The proxy-url must begin with |
371 | Sets the default proxy server to use. The proxy-url must begin with |
367 | a string of the form "http://host:port", croaks otherwise. |
372 | a string of the form "http://host:port", croaks otherwise. |
368 | |
373 | |
369 | To clear an already-set proxy, use "undef". |
374 | To clear an already-set proxy, use "undef". |
|
|
375 | |
|
|
376 | When AnyEvent::HTTP is laoded for the first time it will query the |
|
|
377 | default proxy from the operating system, currently by looking at |
|
|
378 | "$ENV{http_proxy"}. |
370 | |
379 | |
371 | AnyEvent::HTTP::cookie_jar_expire $jar[, $session_end] |
380 | AnyEvent::HTTP::cookie_jar_expire $jar[, $session_end] |
372 | Remove all cookies from the cookie jar that have been expired. If |
381 | Remove all cookies from the cookie jar that have been expired. If |
373 | $session_end is given and true, then additionally remove all session |
382 | $session_end is given and true, then additionally remove all session |
374 | cookies. |
383 | cookies. |
… | |
… | |
456 | SHOWCASE |
465 | SHOWCASE |
457 | This section contaisn some more elaborate "real-world" examples or code |
466 | This section contaisn some more elaborate "real-world" examples or code |
458 | snippets. |
467 | snippets. |
459 | |
468 | |
460 | HTTP/1.1 FILE DOWNLOAD |
469 | HTTP/1.1 FILE DOWNLOAD |
461 | Downloading files with HTTP cna be quite tricky, especially when |
470 | Downloading files with HTTP can be quite tricky, especially when |
462 | something goes wrong and you want tor esume. |
471 | something goes wrong and you want to resume. |
463 | |
472 | |
464 | Here is a function that initiates and resumes a download. It uses the |
473 | Here is a function that initiates and resumes a download. It uses the |
465 | last modified time to check for file content changes, and works with |
474 | last modified time to check for file content changes, and works with |
466 | many HTTP/1.0 servers as well, and usually falls back to a complete |
475 | many HTTP/1.0 servers as well, and usually falls back to a complete |
467 | re-download on older servers. |
476 | re-download on older servers. |