HTTP headers for posting data
Dave Cragg
dcragg at lacscentre.co.uk
Tue Jun 10 16:11:01 EDT 2003
At 10:16 pm +0200 10/6/03, Andre Rombauts wrote:
>Thanks Dave: working...!
>But anyway can someone give an example of HTTPHeaders usage?
>
When you use get or post with an http url, the libUrl library script
constructs a minimal set of headers. For example, if you use the
following command:
get url "http://192.168.123.7/cgi-bin/echo3.mt"
this is the request that is sent to the http server:
GET /cgi-bin/echo3.mt HTTP/1.1
Host: 192.168.123.7
User-Agent: Revolution (MacOS)
The first line is the "request" line. The 2nd and 3rd are the headers.
If you wanted to change the User-Agent header to your own custom
name, you could do this:
set the httpHeaders to "User-Agent: DavesApp 1.0"
get url "http://192.168.123.7/cgi-bin/echo3.mt"
and the request sent to the server will look like this:
GET /cgi-bin/echo3.mt HTTP/1.1
Host: 192.168.123.7
User-Agent: DavesApp 1.0
Setting multiple header lines is done in one go like this:
put "User-Agent: DavesApp 1.0" into tHeaders
put return & "Connection: close" after tHeaders
set the httpHeaders to tHeaders
get url "http://192.168.123.7/cgi-bin/echo3.mt"
The request will look like this:
GET /cgi-bin/echo3.mt HTTP/1.1
Host: 192.168.123.7
User-Agent: DavesApp 1.0
Connection: close
(The Connection header asks the server to close the connection
immediately after the respone has been sent.)
The standard http headers are described in the http rfc.
<http://www.w3.org/Protocols/rfc2616/rfc2616.html>
In addition, you can create custom headers which you can use in
custom web applications. A CGI script on the server can respond
depending on the value of a particular header.
For example:
set the httpheaders to "MyAction: newSessionKey"
This would have no effect unless the server or server script were
specifically looking for this header.
Cheers
Dave
More information about the use-livecode
mailing list