Difference between revisions of "Ns http"

From AOLserver Wiki
Jump to navigation Jump to search
m (formatting tweaks)
m (fix wikitext for code examples)
Line 27: Line 27:
 
Valid HTTP GET:
 
Valid HTTP GET:
  
   % set id [[ns_http queue GET http://aolserver.com/]]
+
<pre>
 +
   % set id [ns_http queue GET http://aolserver.com/]
 
   http0
 
   http0
   % set status [[ns_http wait $id results]]
+
   % set status [ns_http wait $id results]
 
   1
 
   1
 
   % string range $results 0 60
 
   % string range $results 0 60
 
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN
 
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN
 +
</pre>
  
 
Timed out HTTP GET:
 
Timed out HTTP GET:
  
   % set id [[ns_http queue GET http://aolserver.com:12345/]]
+
<pre>
 +
   % set id [ns_http queue GET http://aolserver.com:12345/]
 
   http0
 
   http0
   % set status [[ns_http wait $id results 0]]
+
   % set status [ns_http wait $id results 0]
 
   0
 
   0
 
   % set results
 
   % set results
 
   timeout
 
   timeout
 +
</pre>
  
 
Bogus HTTP GET:
 
Bogus HTTP GET:
  
 +
<pre>
 
   % catch {ns_http queue GET http://nonexistant.domain/} err
 
   % catch {ns_http queue GET http://nonexistant.domain/} err
 
   1
 
   1
 
   % set err
 
   % set err
 
   could not connect to : http://nonexistant.domain/
 
   could not connect to : http://nonexistant.domain/
 +
</pre>
  
 
'''SEE ALSO'''
 
'''SEE ALSO'''

Revision as of 20:10, 9 September 2006

<manpage>ns_http</manpage>

NAME

ns_http - Simple HTTP client functionality

SYNOPSIS

ns_http option ?arg arg ...?

DESCRIPTION

This command provides a simple HTTP client mechanism.
The legal options (which may be abbreviated) are:
  • ns_http cancel id
  • ns_http cleanup
  • ns_http queue method url ?body? ?headers?
body is the value which will be sent as the HTTP request body. headers is the ns_set ID containing the additional headers to include in the HTTP request.
  • ns_http wait id resultsVar ?timeout? ?headers? ?-servicetime svcTime?
resultsVar is the name of a variable that should be used to store the HTTP response body. Default timeout is "2:0" (2s, 0usec). headers is the ns_set ID which will receive the headers from the HTTP response.

EXAMPLES

Valid HTTP GET:

  % set id [ns_http queue GET http://aolserver.com/]
  http0
  % set status [ns_http wait $id results]
  1
  % string range $results 0 60
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN

Timed out HTTP GET:

  % set id [ns_http queue GET http://aolserver.com:12345/]
  http0
  % set status [ns_http wait $id results 0]
  0
  % set results
  timeout

Bogus HTTP GET:

  % catch {ns_http queue GET http://nonexistant.domain/} err
  1
  % set err
  could not connect to : http://nonexistant.domain/

SEE ALSO

ns_httpopen