Http async

From EggWiki
Jump to navigation Jump to search

The ::http::geturl command blocks until the operation completes, unless the -command option specifies a callback that is invoked when the HTTP transaction completes.

package require http

proc httpCallback {token} {
  regexp {(?i)<title>([^<>]+)} [http::data $token] -> title
  http::cleanup $token
  puts "Title was \"$title\""
}

set token [::http::geturl http://netbsd.org -timeout 10000 -command httpCallback]