Welcome, guest | Sign In | My Account | Store | Cart

Simplified HTTP URL retrieval using TclCurl. URL is in the format "yoursite.com/dir1/dir2/file.xml

Tcl, 55 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#####################################################
# Proc - Get URL 
#####################################################
proc getUrl {url proxyHost proxyport userid password receiveFile } {

   package require TclCurl

   puts "\n get url $url\n"

   puts "proxyhost    = $proxyHost   " 
   puts "proxyport    = $proxyport   " 

   set curlHandle [ ::curl::init ]
   
   $curlHandle configure -url               $url \
         	         -userpwd           $userid:$password \
                         -verbose           1 \
         	         -proxy             $proxyHost \
         	         -proxyport         $proxyport \
         	         -proxytype         http \
			 -errorbuffer       errorBuffer \
			 -file              $receiveFile \
			 -failonerror       1 \
         	         -followlocation    1 

                         # -verbose           1 \

   if { [ catch { $curlHandle perform } r ] == 0 } {

           set continue true

       } else {

           $curlHandle cleanup 
           return -code error "$r $errorBuffer"

   }

   set totalTime    [ $curlHandle getinfo totaltime     ] 
   set connectTime  [ $curlHandle getinfo connecttime   ] 
   set sizeDownload [ $curlHandle getinfo sizedownload  ] 
   set speedDownoad [ $curlHandle getinfo speeddownload ] 

   puts " totalTime    = $totalTime    "
   puts " connectTime  = $connectTime  "
   puts " sizeDownload = $sizeDownload "
   puts " speedDownoad = $speedDownoad "

   set details [ list $totalTime $connectTime $sizeDownload $speedDownoad ]

   $curlHandle cleanup 
 
   return [ list $r $details ]

}
Created by Patrick Finnegan on Mon, 5 Sep 2005 (MIT)
Tcl recipes (162)
Patrick Finnegan's recipes (56)

Required Modules

  • (none specified)

Other Information and Tasks