SYNOPSIS
ns_geturl URL ?headersSetId?
DESCRIPTION
This command retrieves the contents of the specified URL. The URL must be a remote http server, or a file relative to the pageroot (begins with /). It does not handle a relative request or follow redirects. The headerSetId option is a variable containing an ns_set Id (not expanded with a $) used to store the remote server headers (see example). ns_geturl only support HTTP version 1.0.
EXAMPLES
-
set page [ns_geturl "www.aolserver.com"] ns_return 200 text/html $page
This fetches the contents of www.aolserver.com and returns that page to the client.
-
set headers [ns_set new] set page [ns_geturl "www.aolserver.com" headers] for {set i 0} {$i < [ns_set size $headers]} {incr i} { ns_puts "Key: [ns_set key $headers $i]" ns_puts "Value: [ns_set value $headers $i]" }
This time, a blank headerset is passed to ns_geturl so we can retrieve the headers of the remote page, which we print out to the client.
-
set file [ns_geturl "/foo/bar.html"] ns_return 200 text/html $file
This example fetches the /foo/bar.html file relative to the pageroot and returns it to the client.
KEYWORDS