1. 依赖包文件
http.tcl 已经默认安装在tcl的core中,可以使用package require http加载tcl的http模块。
2. 使用方式
#!/bin/sh
#command \
exec tclsh "$0" "$@"
#URl配置
set TEST_URL "http://127.0.0.1:8888/cgi-bin/test_cgi"
#0: 发明文xml, 1: 发转义后的xml
set XMLBodyType 1
proc SendHttp args {
global TEST_URL XMLBodyType token
if { $XMLBodyType == 0 } {
set postMessage [lindex $args 0]
} else {
set postMessage [::http::formatQuery testdata [lindex $args 0]]
}
if {[catch {set token [::http::geturl $TEST_URL -query $postMessage]} errMsg]} {
puts "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"} {
set errMsg "RecvHttp Error: http connect timeout"
puts "$errMsg"
: