Artifact [8c03199b32]

Artifact 8c03199b32386a7c5673f7222d41c0f1ab412b8ce3ef63358d9c49e1b90bbd3f:


#################################################
#
# Download webpage using HTTP package
#
#################################################

package require Tcl 8.6-
package require tls
package require http

set url "https://www.tcl.tk/"
set port 443
set protocol "http/1.1"

# Register https protocol handler with http package
http::register https 443 [list ::tls::socket -autoservername 1 -require 1 -alpn [list [string tolower $protocol]]]

# Get webpage
set token [::http::geturl $url -blocksize 16384]
if {[http::status $token] ne "ok"} {
    puts [format "Error: \"%s\"" [http::status $token]]
    ::http::cleanup $token
    exit
}

# Get web page
set data [http::data $token]

# Cleanup
::http::cleanup $token

# Save data to file
set ch [open "tcl_tk_home.html" wb]
puts $ch $data
close $ch