version 6.7
GET HTTP HEADER (header|fieldArray{; valueArray})
Parameter | Type | Description | |
header|fieldArray | Text|Text Array | Request HTTP header or HTTP header fields | |
valueArray | Text Array | HTTP header fields content |
Description
The GET HTTP HEADER command returns either a string or two arrays, containing the HTTP header used for the currently processed request.
This command works only in non-contextual mode. It can be called from within any method (On Web Connection Database Method or On Web Authentication Database Method, method called by '/4DACTION'...) executed in a Web process in a non-contextual mode. If GET HTTP HEADER is called in contextual mode, it returns empty strings.
First syntax: GET HTTP HEADER (header)
When this syntax is used, the result returned in the header variable is as follows:
"GET /page.html HTTP\1.0"+Char(13)+Char(10)+"User-Agent: browser"+
Char(13)+Char(10)+"Cookie: C=HELLO"
Each header field is separated by a CR+LF (Carriage return+Line feed) sequence under Windows and Mac OS.
Second syntax: GET HTTP HEADER (fieldArray; valueArray)
When this syntax is used, the returned results in the fieldArray and valueArray are as follows:
fieldArray{1} = "X-METHOD" | valueArray{1} = "GET" * |
fieldArray{2} = "X-URL" | valueArray{2} = "/page.html" * |
fieldArray{3} = "X-VERSION" | valueArray{3} = "HTTP/1.0" * |
fieldArray{4} = "User-Agent" | valueArray{4} = "browser" |
fieldArray{5} = "Cookie" | valueArray{5} = "C=HELLO" |
* These first three items are not HTTP fields. They are part of the first line of the request.
To comply with the HTTP standard, field names are always written in English.
Here is a list of some HTTP fields that can be used in a request:
Accept: content allowed by the browser.
Accept-Language: language(s) that can be used by the browser (for information). Allows to select a web page using the language defined in the browser.
Cookie: cookies list
From: browser user email address.
Host: server name or address (for example using an URL, http://mywebserver/mypage.html, Host takes the «mywebserver» value). Allows to manage several names pointing towards the same IP address (virtual hosting).
Referer: request origin (for example http://mywebserver/mypage1.html), i.e. the page which is displayed when clicking on the Previous button.
User-Agent: browser or proxy name and version.
Example
The following method allows getting any HTTP request header field content:
` Project method GetHTTPField ` GetHTTPField (Text) -> Text ` GetHTTPField (HTTP header name) -> HTTP header content C_TEXT($0;$1) C_LONGINT($vlItem) ARRAY TEXT($names;0) ARRAY TEXT($values;0) $0:="" GET HTTP HEADER($names;$values) $vlItem:=Find in array($names;$1) If ($vlItem>0) $0:=$values{$vlItem} End if
Once this project method has been written, it can be called as follows:
` Cookie header content $cookie:=GetHTTPField("Cookie")
You can send different pages according to the language set in the browser (for example in the On Web Connection Database Method):
$language:=GetHTTPField("Accept-Language") Case of : ($language="@fr@") `French (see list ISO 639) SEND HTML FILE("index_fr.html") : ($language="@sp@") `Spanish (see list ISO 639) SEND HTML FILE("index_es.html") Else SEND HTML FILE("index.html") End case
Note: Web browsers allow defining several languages by default. They are listed in the "Accept-Language" field, separated by a ";". Their priority is defined according to their position within the string; therefore it is a good idea to test language positions in the string.
Here is an example of virtual hosts (for example, in the On Web Connection Database Method). The following names "home_site.com", "home_site1.com" and "home_site2.com" are directed towards the same IP address, for example 192.1.2.3.
$host:=GetHTTPField("Host") Case of : ($host="www.site1.com") SEND HTML FILE("home_site1.com") : ($host="www.site2.com") SEND HTML FILE("home_site2.com") Else SEND HTML FILE("home_site.com") End case
See Also
GET HTTP BODY, SET HTTP HEADER.