Scroll to navigation

ns_geturl(3aolserver) AOLserver Built-In Commands ns_geturl(3aolserver)


ns_geturl - commands


ns_geturl URL ?headersSetId?


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.


set page [ns_geturl ""]
ns_return 200 text/html $page

This fetches the contents of and returns that page to the client.

set headers [ns_set new]
set page [ns_geturl "" 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.


nsd(1), info(n), ns_set(n), ns_httpget(n)


4.0 AOLserver