Reading from a URL, and reading Json, from your Tcl script
Archive - Originally posted on "The Horse's Mouth" - 2015-03-12 22:35:27 - Graham EllisYou can read from a URL in Tcl using the http package ... for example
package require http
set handle [::http::geturl http://www.wellho.co.uk/robots.txt]
And you can then collect the data:
set body [::http::data $handle]
and the http status code:
set stat [::http::ncode $handle]
and the headers:
set headers [::http::meta $handle]
See [here] for the complete source code and sample output. The http::configure command gives a wide variety of configuration options too.
A further example - [here] - picks up json data via http, and converts it into a Tcl structure which it then displays. Of course, once you have the data, you can do just about anything with it.