Artifact
8c03199b32386a7c5673f7222d41c0f1ab412b8ce3ef63358d9c49e1b90bbd3f:
0000: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0010: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0020: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0030: 23 0a 23 0a 23 20 44 6f 77 6e 6c 6f 61 64 20 77 #.#.# Download w
0040: 65 62 70 61 67 65 20 75 73 69 6e 67 20 48 54 54 ebpage using HTT
0050: 50 20 70 61 63 6b 61 67 65 0a 23 0a 23 23 23 23 P package.#.####
0060: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0070: 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 ################
0080: 23 23 23 23 23 23 23 23 23 23 23 23 23 0a 0a 70 #############..p
0090: 61 63 6b 61 67 65 20 72 65 71 75 69 72 65 20 54 ackage require T
00a0: 63 6c 20 38 2e 36 2d 0a 70 61 63 6b 61 67 65 20 cl 8.6-.package
00b0: 72 65 71 75 69 72 65 20 74 6c 73 0a 70 61 63 6b require tls.pack
00c0: 61 67 65 20 72 65 71 75 69 72 65 20 68 74 74 70 age require http
00d0: 0a 0a 73 65 74 20 75 72 6c 20 22 68 74 74 70 73 ..set url "https
00e0: 3a 2f 2f 77 77 77 2e 74 63 6c 2e 74 6b 2f 22 0a ://www.tcl.tk/".
00f0: 73 65 74 20 70 6f 72 74 20 34 34 33 0a 73 65 74 set port 443.set
0100: 20 70 72 6f 74 6f 63 6f 6c 20 22 68 74 74 70 2f protocol "http/
0110: 31 2e 31 22 0a 0a 23 20 52 65 67 69 73 74 65 72 1.1"..# Register
0120: 20 68 74 74 70 73 20 70 72 6f 74 6f 63 6f 6c 20 https protocol
0130: 68 61 6e 64 6c 65 72 20 77 69 74 68 20 68 74 74 handler with htt
0140: 70 20 70 61 63 6b 61 67 65 0a 68 74 74 70 3a 3a p package.http::
0150: 72 65 67 69 73 74 65 72 20 68 74 74 70 73 20 34 register https 4
0160: 34 33 20 5b 6c 69 73 74 20 3a 3a 74 6c 73 3a 3a 43 [list ::tls::
0170: 73 6f 63 6b 65 74 20 2d 61 75 74 6f 73 65 72 76 socket -autoserv
0180: 65 72 6e 61 6d 65 20 31 20 2d 72 65 71 75 69 72 ername 1 -requir
0190: 65 20 31 20 2d 61 6c 70 6e 20 5b 6c 69 73 74 20 e 1 -alpn [list
01a0: 5b 73 74 72 69 6e 67 20 74 6f 6c 6f 77 65 72 20 [string tolower
01b0: 24 70 72 6f 74 6f 63 6f 6c 5d 5d 5d 0a 0a 23 20 $protocol]]]..#
01c0: 47 65 74 20 77 65 62 70 61 67 65 0a 73 65 74 20 Get webpage.set
01d0: 74 6f 6b 65 6e 20 5b 3a 3a 68 74 74 70 3a 3a 67 token [::http::g
01e0: 65 74 75 72 6c 20 24 75 72 6c 20 2d 62 6c 6f 63 eturl $url -bloc
01f0: 6b 73 69 7a 65 20 31 36 33 38 34 5d 0a 69 66 20 ksize 16384].if
0200: 7b 5b 68 74 74 70 3a 3a 73 74 61 74 75 73 20 24 {[http::status $
0210: 74 6f 6b 65 6e 5d 20 6e 65 20 22 6f 6b 22 7d 20 token] ne "ok"}
0220: 7b 0a 20 20 20 20 70 75 74 73 20 5b 66 6f 72 6d {. puts [form
0230: 61 74 20 22 45 72 72 6f 72 3a 20 5c 22 25 73 5c at "Error: \"%s\
0240: 22 22 20 5b 68 74 74 70 3a 3a 73 74 61 74 75 73 "" [http::status
0250: 20 24 74 6f 6b 65 6e 5d 5d 0a 20 20 20 20 3a 3a $token]]. ::
0260: 68 74 74 70 3a 3a 63 6c 65 61 6e 75 70 20 24 74 http::cleanup $t
0270: 6f 6b 65 6e 0a 20 20 20 20 65 78 69 74 0a 7d 0a oken. exit.}.
0280: 0a 23 20 47 65 74 20 77 65 62 20 70 61 67 65 0a .# Get web page.
0290: 73 65 74 20 64 61 74 61 20 5b 68 74 74 70 3a 3a set data [http::
02a0: 64 61 74 61 20 24 74 6f 6b 65 6e 5d 0a 0a 23 20 data $token]..#
02b0: 43 6c 65 61 6e 75 70 0a 3a 3a 68 74 74 70 3a 3a Cleanup.::http::
02c0: 63 6c 65 61 6e 75 70 20 24 74 6f 6b 65 6e 0a 0a cleanup $token..
02d0: 23 20 53 61 76 65 20 64 61 74 61 20 74 6f 20 66 # Save data to f
02e0: 69 6c 65 0a 73 65 74 20 63 68 20 5b 6f 70 65 6e ile.set ch [open
02f0: 20 22 74 63 6c 5f 74 6b 5f 68 6f 6d 65 2e 68 74 "tcl_tk_home.ht
0300: 6d 6c 22 20 77 62 5d 0a 70 75 74 73 20 24 63 68 ml" wb].puts $ch
0310: 20 24 64 61 74 61 0a 63 6c 6f 73 65 20 24 63 68 $data.close $ch
0320: 0a 0a ..