#!/usr/bin/tclsh

package require http
package require tls

http::register https 443 tls::socket

set url https://image.buienradar.nl/2.0/image/sprite/RadarMapRainNL

set tok [http::geturl $url]
set code [http::ncode $tok]
if {$code in {301 302}} {
    set str [lsearch -nocase -exact -inline [http::meta $tok] location]
    set loc [dict get [http::meta $tok] $str]
    http::cleanup $tok
    set tok [http::geturl $loc]
    set code [http::ncode $tok]
}
dict for {key val} [http::meta $tok] {
    puts "$key $val"
}
set f [open /tmp/buienradar.png wb]
puts -nonewline $f [http::data $tok]
http::cleanup $tok
