http
http::geturl url ?-option value ...?
The http package 2.9.8 of the Tcl library, with package require http: an HTTP/1.1 client on the sockets of ztcl. http::geturl sends a GET, a POST with -query or -querychannel, or a HEAD with -validate 1, and gives a token, the name of an array with the status, the headers, and the body of the reply. With -command the request runs in the event loop and the command gets the token at the end. http::config sets the proxy, the user agent, and the other defaults, http::formatQuery encodes a query, and http::status, http::ncode, http::meta, http::data, and http::cleanup read and free a token. A request with -keepalive 1 uses one persistent socket for each host and port. https URLs use the TLS channels of ztcl::tls. package require http 1.0 gives the old commands http_get, http_config, and the others.
This page also has http::config, http::geturl, http::formatQuery, http::quoteString, http::reset, http::wait, http::status, http::size, http::code, http::ncode, http::meta, http::data, http::error, http::cleanup, http::register, http::registerError, http::unregister.
Examples
package require httpgives2.9.8http::formatQuery name "a b" x &givesname=a%20b&x=%26
Facts
- Capability:
package. A new interpreter does not have this command. See Limits and capabilities. - Compute cost: one compute unit for the call, and more for the commands that it runs.
Differences from Tcl 8.6
- The requests on one persistent socket go one after the other, so
-pipelinedoes not change the order on the socket. The codings gzip, deflate, and compress need thezlibcommand, so the default Accept-Encoding is identity.