1. HTTPS Script

An example HTTPS script is shown. Modify the URL to your own URL. The example will fetch the URL in a loop for 10 iterations and report the time taken.

#!./bin/tclsh8.6
      package require http
      package require tls
      #package require twapi_crypto

proc http::Log {args} {
puts $args
}

proc cb {token}  {
if { [ http::status $token ] != "ok" } { error "Response not OK [ http::error $token]" } else {
http::cleanup $token
   }
set ::done 1
}


set url "https://MYURL"
#http::register https 443 [list ::twapi::tls_socket -async ]
http::register https 443 [list ::tls::socket -async -tls1 1 -ssl3 false -ssl2 false -autoservername true ]

set response [ http::geturl $url -keepalive true ]
    puts [ http::status $response ]
    set so [ lsearch -inline [ chan names ] sock* ]

chan configure $so -buffering none -encoding binary -blocking 1 -translation crlf -eofchar {{} {}}
      ::tls::handshake $so
     puts [ ::tls::status $so ]

chan configure $so -buffering full -buffersize 8192 -encoding binary -blocking 0 -translation crlf -eofchar {{} {}}
        set test_count 10
        set response_count 0
        set total_time 0
        set start_time [clock milliseconds]
        for {set i 0} {$i < $test_count} {incr i} {
            set start_time [clock milliseconds]
          set ::done 0
set response [ http::geturl $url -binary true -blocksize 8192 -timeout 10000 -keepalive true -command cb ]        
vwait ::done
            set end_time [clock milliseconds]
            set elapsed [expr {$end_time - $start_time}]
            incr total_time $elapsed
            puts "Call $i took $elapsed"
            }
            set end_time [clock milliseconds]
puts "$test_count iterations in $total_time at an average of [expr {$total_time / $test_count}]"