What: | TclCurl: "curl" is a "command line tool for transferring files with URL syntax" |
Where: | http://personal.telefonica.terra.es/web/getleft/tclcurl/index.html (for TclCurl) (link broken 2013-10-20) http://curl.haxx.se/ (for curl, libcurl) |
Description: | Tcl binding for libcurl, a library for accessing internet resources of various types. Supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE, LDAP, LDAPS, IMAP, IMAPS, POP, POP3, SMTP, SMTPS and gopher. libcurl is currently at version 7.30.0 while minimum required version is 7.21.4 and TclCurl is currently at version 7.22.0. |
Updated: | 5/2013 |
Contact: | fandom at telefonica.net (Andres Garcia) |
More background is available in "curl Simplifies Web Retrieval" (http://www.unixreview.com/documents/s=1820/uni1011713175619/0201i.htm ). (link broken 2013-10-20. Try http://web.archive.org/web/20071126031437/www.unixreview.com/documents/s=1820/uni1011713175619/0201i.htm )
Note that at least according to the Wikipedia article (http://en.wikipedia.org/wiki/UNIX_Review ), "UnixReview.com website is no longer active and the archives have been destroyed or hidden." Clicking the link redirects the browser to a different domain and incorrectly strips off the / after ".com" (which creates a nonexistent domain name).
The original site appears to be gone.
An up-to-date mirror is at https://github.com/flightaware/tclcurl-fa
also here: https://github.com/jdc8/tclcurl , with some updates for Curl 7.80.0 ( per https://groups.google.com/forum/#!topic/comp.lang.tcl/s4P05GDddl4 )
So, how is TclCurl better than the bare http (or ftp) package? A few examples should help make that clear [ WWW::Search::* analogue; HotMail mass downloader]. But, wouldn't either of those examples be just as feasible to implement with the http package?
You cannot GET a https page if you are sitting behind a proxy using the bare http package. I haven't tried TclCurl yet. US
Most of the time you are right, the http package is complete enough to satisfy most users, TclCurl does provide more features, but unless you need them, you'd better use the http package and forget about the lack of portability a C extension brings.
But as I said, TclCurl does have more features; for example, you can tunnel non-http request through a http proxy. I haven't tried it myself, but it should be something like:
curl::transfer -url https://www.securedomain.com -file index.html \ -httpproxytunnel 1 -proxy 192.168.0.1:80
I don't have a proxy to test this- could someone please check whether it works?
TclCurl supports http 1.1, including keep-alive and resumed transfers, though there is work by Pat Thoyts to add 1.1 support to a new version of the http package, which you can get at http://tclsoap.sourceforge.net/http.html
As for the rest of the TclCurl features, some would be trivial to implement in Tcl, like being able to follow redirections, some a little bit harder, like cookie support, but the principle is always the same: check the features you need and, if the http package offers them, use it, but if it doesn't, check TclCurl.
Apart from http(s), TclCurl also offers support for other protocols, like ldap, gopher, ftp, ... but I have never used the pure Tcl clients, so I have no idea how they compare.
Even though they have not been written with TclCurl in mind, you may want to read http://curl.haxx.se/docs/httpscripting.html and http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
They will give you an idea of what can be done using TclCurl.
Andres
I believe the TclCurl package would be more popular if there were more examples. Below is an example on how to manually package up a Soap XML envelope over http, set http headers, and parse the Soap response using regexp. Overall, TclCurl's performance seems very fast.
Scott Nichols scott dot nichols4 at comcast dot net
if { [catch { package require TclCurl set soapEnv { <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" > <SOAP-ENV:Body> <ns1:getTemp xmlns:ns1="urn:xmethods-Temperature" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <zipcode xsi:type="xsd:string">11217</zipcode> </ns1:getTemp> </SOAP-ENV:Body> </SOAP-ENV:Envelope>} puts $soapEnv # Build Http Headers. set httpHeaders "" lappend httpHeaders "Content-Type: text/xml; charset=utf-8" lappend httpHeaders "SoapAction: GetTemperature for zip" puts $httpHeaders set httpBody "" set response [::curl::transfer -url http://services.xmethods.net:80/soap/servlet/rpcrouter \ -post 1 \ -postfields $soapEnv \ -httpheader $httpHeaders \ -bodyvar httpBody] puts "Soap Response: $response" puts "Soap Body: $httpBody" set rExp {<return xsi:type="xsd:float">(.*?)</return>} set temp 0 regexp $rExp $httpBody sMatch temp puts "Current Temp for zip 11217 is $temp degrees" puts "------------------------------------------------------------------------" } errorString] } { puts "Error: $errorString" set bSuccess 0 puts "------------------------------------------------------------------------" }
Example procs to GET and POST ~ BvW
proc http_get {url args} { set pairs {} foreach {name value} $args { lappend pairs "[curl::escape $name]=[curl::escape $value]" } append url ? [join $pairs &] set curlHandle [curl::init] $curlHandle configure -url $url -bodyvar html catch { $curlHandle perform } curlErrorNumber if { $curlErrorNumber != 0 } { error [curl::easystrerror $curlErrorNumber] } $curlHandle cleanup return $html } proc http_post {url args} { set pairs {} foreach {name value} $args { lappend pairs "[curl::escape $name]=[curl::escape $value]" } set data [join $pairs &] set curlHandle [curl::init] $curlHandle configure -url $url -bodyvar html -post 1 -postfields $data catch { $curlHandle perform } curlErrorNumber if { $curlErrorNumber != 0 } { error [curl::easystrerror $curlErrorNumber] } $curlHandle cleanup return $html }
APN For a single retrieval, the curl::transfer command may be simpler than using Curl handles. For example,
curl::transfer -url $url -bodyvar html
is equivalent to above http_get procedure.
HaO 2013-05-06: Install TclCurl 7.22.0 on: CentOS 6 64bit with 'config.site' from [L1 ].
The curl version provided by CentOS is 7.19.7 while TclCurl requires 7.21.4 -> install curl 8.30.0 first:
./configure make sudo make install
Installs libcurl '/usr/local/lib64/libcurl.so.4.3.0' and the development files in '/usr/local/include/curl'.
Now, compilation of TclCurl works fine:
./configure --with-tcl=/usr/local/lib64 make sudo make install
Installs tclcurl in folder '/usr/local/lib64/TclCurl7.22.0'.
%package require TclCurl 7.22.0
pi31415 2022-09-14: Install TclCurl 7.22.0 on Slackware 15.0
$ curl -o tclcurl.tgz gopher://tilde.pink/9/~bencollver/files/tclcurl.tgz