XML Script logo up prev
Socket connections
Overview

X-Tract can also make its own calls to remote web-servers, using the _socket command. This example describes how to use _socket to implement HTTP, but the command can be used for any remote, port-based, operation.

HTTP headers

These two schematics show the most basic HTTP headers that might be used to pass CGI information onto a remote server, or, with an empty query string, just request an HTML file (note that both _eval and _data both already support calling a URL using HTTP, if you wish to load a remote file into your template's environment). The full HTTP specification is available at the W3C site: to comply with the HyperText Transfer Protocol, a POST request requires a Content-Type: header, in order that the server knows that the body has been CGI-encoded.


GET /~dir/file?qry=stg HTTP/1.1 POST /~homedir/file HTTP/1.1
User-Agent: X-Tract 1.0         User-Agent: X-Tract 1.0
Host: remote.host.ip            Host: remote.host.ip
                                Content-length: \#number
(two return characters
  in a row.)                    (two return characters
                                  in a row.)
                                CONTENT -- CGI-ENCODED
Opening a socket

If the above is plain-text content of the object http_header on the data side, including the two return characters (non-obvious in the GET case!) then we can open a socket and connect thus:


<_socket 
  port="80" store="store_object" 
  timeout="30" host="remote.host.ip">

  <write ># \http_header #</write>

  <read_all />

</_socket>
Notes

The above code reads the incoming HTTP-Response (which is generally unencoded, but conforms to various standards as regards the scope of the ASCII that can be included) and puts it into a store_object object on the data tree at the current point of the tree.

Tip

For further documentation of socket calls, see the ICE-X package and its associated documentation.

Contents...

XML Script homepage | Documentation home | XML Script docs | Command list | Function list | X-Tract docs

X-Stream, X-Tract and XML Script are trade marks of DecisionSoft Limited
© Copyright 1998-2000 DecisionSoft Limited