Fields property

This property of HttpConnection object gets access to the client's request header fields and to the server response headers.

Changing request headers

If you write into the object (change or add object item) then you set the information headers which will be passed to in the HTTP request by the next FetchData call. This code shows how to set request headers. For example, let ask the server to return only first 1024 bytes of document:

Set tcpip=CreateObject("SHOTIP.Connection")
tcpip.http.Fields("Range")="bytes=0-1023"
tcpip.http.FetchData("http:// ...")

Also, you can access the Field object more easy, using the short form. For example, the following three strings are equivalent:

tcpip.http("MyCustomField")="What a beautiful day!"
tcpip.http.Fields("MyCustomField")="What a beautiful day!"
tcpip.http.Fields.Item("MyCustomField")="What a beautiful day!"

As a rule, the custom fields (not defined by HTTP protocol) can be accessible in the script using HTTP_name server variable. For example, the previous field can be retrieved in the ASP script (used in the next FetchData call) using the following string:

myvar = Request.ServerVariables("HTTP_MYCUSTOMFIELD")

This feature can be used to pass additional information into Web scripts.

Retrieving response headers

To get response header fields information you should read the Fields object items after FetchData call. For example, to get information about server type you can use the following string:

tcpip.http.FetchData("http:// ...")
servertype = tcpip.http("Server")

To enumerate and get all headers returned by server, you can use the for each construnction:

tcpip.http.FetchData("http:// ...")
For each f in tcpip.http.Fields
 name = f
 value = tcpip.http(f)
Next

Also, the Count property of Fields object returns amount of fields in the response header:

a = tcpip.http.Fields.Count