ad_httpget (public, deprecated)

 ad_httpget [ -url url ] [ -headers headers ] [ -timeout timeout ] \
    [ -depth depth ]

Defined in packages/acs-tcl/tcl/deprecated-procs.tcl

Deprecated. Invoking this procedure generates a warning.

Just like ns_httpget, but first headers is an ns_set of headers to send during the fetch. ad_httpget also makes use of Conditional GETs (if called with a Last-Modified header). Returns the data in array get form with array elements page status modified.

Switches:
-url (optional)
-headers (optional)
-timeout (optional, defaults to "30")
-depth (optional, defaults to "0")
See Also:

Testcases:
No testcase defined.
Source code:
ad_log_deprecated proc ad_httpget
    ns_log debug "Getting {$url} {$headers} {$timeout} {$depth}"

    if {[incr depth] > 10} {
        return -code error "ad_httpget:  Recursive redirection:  $url"
    }

    lassign [ns_httpopen GET $url $headers $timeout] rfd wfd headers
    close $wfd

    set response [ns_set name $headers]
    set status [lindex $response 1]
    set last_modified [ns_set iget $headers last-modified]

    if {$status == 302 || $status == 301} {
        set location [ns_set iget $headers location]
        if {$location ne ""} {
            ns_set free $headers
            close $rfd
            return [ad_httpget -url $location -timeout $timeout -depth $depth]
        }
    } elseif$status == 304 } {
        # The requested variant has not been modified since the time specified
        # A conditional get didn't return anything.  return an empty page and
        set page {}

        ns_set free $headers
        close $rfd
    } else {
        set length [ns_set iget $headers content-length]
        if { $length eq "" } {set length -1}

        set type [ns_set iget $headers content-type]
        set_encoding $type $rfd

        set err [catch {
            while 1 {
                set buf [_ns_http_read $timeout $rfd $length]
                append page $buf
                if { "" eq $buf } break
                if {$length > 0} {
                    incr length -[string length $buf]
                    if {$length <= 0} break
                }
            }
        } errMsg]
        ns_set free $headers
        close $rfd

        if {$err} {
            return -code error -errorinfo $::errorInfo $errMsg
        }
    }

    # order matters here since we depend on page content
    # being element 1 in this list in util_httpget
    return [list page $page  status $status  modified $last_modified]
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/acs-tcl/tcl/deprecated-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: