Http(3tcl) Tcl Built-In Commands Http(3tcl) ______________________________________________________________________________ NAME Http - HTTP/1.0 SYNOPSIS package require http ?2.4? ::http::config ?options? ::http::geturl url ?options? ::http::formatQuery list ::http::reset token ::http::wait token ::http::status token ::http::size token ::http::code token ::http::ncode token ::http::data token ::http::error token ::http::cleanup token ::http::register proto port command ::http::unregister proto ______________________________________________________________________________ DESCRIPTION http HTTP/1.0 HTTP/1.0 GETPOST HEAD (proxy) Safesock applets URL (fetching) HTTP HTTPS http::register socket ::http::geturl HTTP (transaction) options () GETPOST HEAD ::http::geturl (token)::http -command HTTP ::http::geturl HTTP (callback)Tcl (active) Tk Tcl ::http::geturl ::http::wait COMMANDS ::http::config ?options? ::http::config HTTP (User- Agent): -accept mimetypes ()()(header) */* mime()"image/gif, image/jpeg, text/*" -proxyhost hostname URL -proxyport number -proxyfilter command ::http::geturl command -proxyhost -proxyport -useragent string HTTP "Tcl http client package 2.2." ::http::geturl url ?options? ::http::geturl -query POST -validate HEAD GET ::http::geturl token () -command HTTP ::http::geturl ::http::geturl : -binary boolean Specifies whether to force interpreting the url data as binary. Normally this is auto-detected (anything not beginning with a text content type or whose content encoding is gzip or compress is considered binary data). -blocksize size URL size -progress () -channel name URL name state(body) -command callback HTTP callback ::http::geturl callback ::http::geturl token (): proc httpCallback {token} { upvar #0 $token state # Access state as a Tcl array } -handler callback HTTP callback () HTTP : HTTP ::http::geturl token : proc httpHandlerCallback {socket token} { upvar #0 $token state # Access socket, and state as a Tcl array ... (example: set data [read $socket 1000];set nbytes [string length $data]) ... return nbytes } -headers keyvaluelist HTTP keyvaluelist (key)(strip)(corrupt) keyvaluelist Pragma no-cache HTTP : Pragma: no-cache -progress callback URL callback: ::http::geturl token Content-Length (meta): proc httpProgress {token total current} { upvar #0 $token state } -query query ::http::geturl query POST query x-url-encoding ::http::formatQuery -queryblocksize size URL (post) size () -queryprogress () -querychannel channelID ::http::geturl channelID POST -type channelID x-url-encoding -headers Content-Length() ::http::geturl -queryprogress callback URL callback (POST)(act) -progress () -timeout milliseconds milliseconds () ::http::geturl (timeout) ::http::reset -command ::http::status timeout -type mime-type mime-type Content-Type () POST (application/x-www-form- urlencoded) -validate boolean boolean ::http::geturl HTTP HEAD URL (meta)() state(meta) STATE ARRAY ::http::formatQuery key value ?key value ...? x-url & = ::http::geturl -query ::http::reset token ?why? token HTTP state(status) why reset -command ::http::wait token vwait ::http::geturl -command ::http::geturl HTTP ::http::data token body (URL ) ::http::error token error ::http::status token status ::http::code token http ::http::ncode token http (200404 ) ::http::size token currentsize ::http::geturl URL ::http::cleanup token token ::http::data HTTP ::http::geturl (leak)(hit)... ::http::register proto port command Tcl channel () HTTP HTTPS: package require http package require tls http::register https 443 ::tls::socket set token [http::geturl https://my.secure.site/] ::http::unregister proto (unregister) http::register(handler) ERRORS http::geturl (raise): URL URL URL HTTP I/O ::http::geturl ( -command) HTTP I/O ::http::geturl ::http::cleanup ::http::geturl HTTP I/O (throw)() HTTP ::http::geturl HTTP ::http::status error ::http::error HTTP (point) ::http::wait () http::cleanup http::status HTTP ok HTTP ok http::code HTTP http::ncode ()(200404 500) http::code "HTTP 404 File not found" eof eof error error ::http::error http::geturl post posterror http::geturl ok eof STATE ARRAY ::http::geturl token Tcl HTTP (construct): upvar #0 $token state url () http::cleanup : body URL -channel ::http::data charset The value of the charset attribute from the Content-Type meta-data value. If none was specified, this defaults to the RFC standard iso8859-1, or the value of $::http::defaultCharset. Incoming text data will be automatically converted from this charset to utf-8. coding A copy of the Content-Encoding meta-data value. currentsize URL ::http::size error HTTP () http HTTP ::http::code : HTTP/1.0 code string code HTTP 200 OK45 3Location URL meta HTTP URL meta : array set meta $state(meta) HTTP Content-Type URL text/htmlimage/gifapplication/postscript application/x-tcl Content-Length (advertise) ::http::geturl state(size) Location URL posterror post status ok(user- reset) resettimeout error() totalsize Content-Length type Content-Type url URL EXAMPLE # Copy a URL to a file and print meta-data proc ::http::copy { url file {chunk 4096} } { set out [open $file w] set token [geturl $url -channel $out -progress ::http::Progress \ -blocksize $chunk] close $out # This ends the line started by http::Progress puts stderr "" upvar #0 $token state set max 0 foreach {name value} $state(meta) { if {[string length $name] > $max} { set max [string length $name] } if {[regexp -nocase ^location$ $name]} { # Handle URL redirects puts stderr "Location:$value" return [copy [string trim $value] $file $chunk] } } incr max foreach {name value} $state(meta) { puts [format "%-*s %s" $max $name: $value] } return $token } proc ::http::Progress {args} { puts -nonewline stderr . ; flush stderr } SEE ALSO safe(n), socket(n), safesock(n) KEYWORDS security policy, socket [] [] 2001/09/20 Linux man : http://cmpp.linuxforum.net man man https://github.com/man-pages-zh/manpages- zh Tcl 8.3 Http(3tcl)