Tcl: 使用TclCurl获取网络内容

风行水上 @ 2010-03-18 14:56:05
标签:

    curl 是一个访问HTTP或FTP的程序。libcurl 是curl所对应的C语言库。 TclCurllibcurl 的Tcl语言绑定。

    使用 TclCurl 获取网络内容方法如下

    set curl [curl::init]
    
    $curl configure -useragent "Mozilla/5.0 Gecko/2008102920 Firefox/3.0.4"    
    
    set query "q=[curl::escape $v]"
    
    $curl configure -httpget 1 -url $request_url -bodyvar responseText   
    
    $curl configure -post 1    -url $url -postfields $query -bodyvar responseText       
    
    set status [$curl perform]                 
    
    if {$status != 0} {
    	puts "ERROR: curl fail\n"
    }
    
    set responseText [encoding convertfrom utf-8 $responseText]
    
    set contenttype [$curl getinfo contenttype]  ; # e.g. text/html OR text/plain
    
    
    

    也可以用异步的curl如下:

    TODO

    标签:

      分享到:
      comments powered by Disqus

      27/32ms