4D v14.3WEB GET HTTP HEADER |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
WEB GET HTTP HEADER
|
WEB 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 | |||||
The WEB GET HTTP HEADER command returns either a string or two arrays, containing the HTTP header used for the currently processed request.
This command can be called from within any method (On Web Authentication Database Method or On Web Connection Database Method, method called by "/4DACTION"...) executed in a Web process.
"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.
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:
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:=""
WEB GET HTTP HEADER($names;$values)
$vlItem:=Find in array($names;$1)
If($vlItem>0)
$0:=$values{$vlItem}
End if
` Cookie header content
$cookie:=GetHTTPField("Cookie")
$language:=GetHTTPField("Accept-Language")
Case of
:($language="@fr@") `French (see list ISO 639)
WEB SEND FILE("index_fr.html")
:($language="@sp@") `Spanish (see list ISO 639)
WEB SEND FILE("index_es.html")
Else
WEB SEND 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.
$host:=GetHTTPField("Host")
Case of
:($host="www.site1.com")
WEB SEND FILE("home_site1.com")
:($host="www.site2.com")
WEB SEND FILE("home_site2.com")
Else
WEB SEND FILE("home_site.com")
End case
Product: 4D
Theme: Web Server
Number:
697
Created: 4D v6.7
Renamed: 4D v13
WEB GET HTTP BODY
WEB SET HTTP HEADER
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)
Inherited from : GET HTTP HEADER ( 4D v12.4)