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}
    }
    

      

  • 相关阅读:
    struts2简介
    项目整合SpringDataRedis
    SpringDataRedis入门Demo
    包管理-rpm
    文件查找与压缩
    N042第一周
    Shell
    Linux下终端字体颜色设置方法
    文本处理工具作业
    正则表达式
  • 原文地址:https://www.cnblogs.com/voipman/p/5048461.html
Copyright © 2011-2022 走看看