Understanding HTTP Headers in Web Connection |
DO WCONNECT
oip = CREATE('wwIPStuff')
oIP.HTTPConnect('www.microsoft.com')
lcData = '
oIP.HTTPGetEx('/',@lcData)
CLEAR
? oIP.cHTTPHeaders
What you should see is something like this:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Content-Location: http://www.microsoft.com/Default.htm
Date: Mon, 24 Apr 2000 20:47:26 GMT
Content-Type: text/html
Accept-Ranges: bytes
Last-Modified: Mon, 24 Apr 2000 18:01:16 GMT
ETag: '1057b71517aebf1:61bb'
Content-Length: 15824
<html>
document content goes here...
</html>
An HTTP header is always made up of individual lines separated by CHR(13) + CHR(10) each and an empty line that separates the HTTP header from the document's content. The content of the document is described in the Content-Type header - in the example above text/html. The content type is extremely important as it tells the client what kind of content to expect. A browser for example looks at the content type to see at how to display the data. So you can send text/xml and be able to view XML or application/pdf to see an Adobe Acrobat document in its viewer.
Every server generated request should output an HTTP header although at minimum it only needs to include a status code and content type:
HTTP/1.1 200 OK
Content-Type: text/html
Content Length can also be useful if you're sending binary data to a client. Clients can use the content length value to figure out how much data they're downloading and potentially provide status information. For Web pages binary downloads require a content length to show you a progress dialog (downloading x of y bytes).
ContentTypeHeader HTMLHeader ExpandTemplate ExpandScriptExample:
Response.ContentTypeHeader() && Writes HTTP Header
Response.Write('<html>')
...
Response.HTMLHeader('Hello World')
Response.Write('<hr>')
...
loHeader = CREATE('wwHTTPHeader')
loHeader.DefaultHeader()
loHeader.AddCookie('wwhome',SYS(2015))
*** To apply the header
Response.Write(loHeader.GetOutput())
Response.Write('<html>')
...
You can also pass an HTTP header object directly to one of the Response methods above that normally create an header automatically. Instead of sending the header output directly into the HTTP stream, pass the loHeader object as a parameter:
Response.ContentTypeHeader(loHeader)
Response.Write('<html>')
or
Response.ExpandTemplate('somepage.wc',loHeader)
loHeader = CREATE('wwHTTPHeader')
loHeader.DefaultHeader()
loHeader.AddCookie('testcookie','rick')
Response.ExpandTemplate('somepage.wc',loHeader)
This causes ExpandScript to use the header you passed instead of the default header it would generate without the parameter.
Last Updated: 04/24/00