util_httppost url formvars { timeout "30" } { depth "0" } { http_referer " " }What it does:
Returns the result of POSTing to another Web server or -1 if there is an error or timeout. formvars should be in the form "arg1=value1&arg2=value2"Defined in: /web/philip/packages/acs-core/utilities-procs.tcl
Source code:
if [catch {
if {[incr depth] > 10} {
return -code error "util_httppost: Recursive redirection: $url"
}
set http [util_httpopen POST $url "" $timeout $http_referer]
set rfd [lindex $http 0]
set wfd [lindex $http 1]
#headers necesary for a post and the form variables
_ns_http_puts $timeout $wfd "Content-type: application/x-www-form-urlencoded \r"
_ns_http_puts $timeout $wfd "Content-length: [string length $formvars]\r"
_ns_http_puts $timeout $wfd \r
_ns_http_puts $timeout $wfd "$formvars\r"
flush $wfd
close $wfd
set rpset [ns_set new [_http_gets $timeout $rfd]]
while 1 {
set line [_ns_http_gets $timeout $rfd]
if ![string length $line] break
ns_parseheader $rpset $line
}
set headers $rpset
set response [ns_set name $headers]
set status [lindex $response 1]
if {$status == 302} {
set location [ns_set iget $headers location]
if {$location != ""} {
ns_set free $headers
close $rfd
return [ns_httpget $location $timeout $depth]
}
}
set length [ns_set iget $headers content-length]
if [string match "" $length] {set length -1}
set err [catch {
while 1 {
set buf [_ns_http_read $timeout $rfd $length]
append page $buf
if [string match "" $buf] break
if {$length > 0} {
incr length -[string length $buf]
if {$length <= 0} break
}
}
} errMsg]
ns_set free $headers
close $rfd
if $err {
global errorInfo
return -code error -errorinfo $errorInfo $errMsg
}
} errmgs ] {return -1}
return $page