zoukankan      html  css  js  c++  java
  • tcl实现http请求

    package require "http"
    
    proc errLog args {
        puts $args
    }
    
    proc SendHttp args {
        global token
        set toUrl [lindex $args 0]
        if {[catch {set token [::http::geturl $toUrl ]} errMsg]} {
            errLog "geturl error: $errMsg"
            return -code -1 "geturl error: $errMsg"
        }
        return "send OK"
    }
    
    proc RecvHttp args {
        global token
        ::http::wait $token
    
        set rStatus [::http::status $token]
        if {$rStatus == "timeout"} {
            errLog "RecvHttp Error: http connect timeout"
            ::http::cleanup $token
            return -code -1 "timeout"
        } elseif {$rStatus == "reset"} {
            errLog "RecvHttp Error: http connect reset"
            ::http::cleanup $token
            return -code -1 "reset"
        } elseif {$rStatus != "ok"} {
            errLog "RecvHttp Error: $rStatus"
            ::http::cleanup $token
            return -code -1 "$rStatus"
        }
        ##############process Responce###################
        set rSize [::http::size $token]
        set rBody [::http::data $token]
        ::http::cleanup $token
    
        errLog "receive message is [encoding convertfrom utf-8 $rBody]"
        return $rBody
    }
    
    set toUrl "http://www.baidu.com"
    puts $toUrl
    if {[catch {SendHttp $toUrl} errMsg]} {
        errLog "SendHttp error: $errMsg"
    } else {
        catch {RecvHttp}
    }
    

      

  • 相关阅读:
    贪婪算法
    递归 快速排序
    递归 判断数组最大数字
    加法递归
    快速排序
    二分查找
    介绍求解AX=b:可解性与解的结构
    消元法求解线性方程组
    内容说明-线性代数
    gis
  • 原文地址:https://www.cnblogs.com/voipman/p/5048461.html
Copyright © 2011-2022 走看看