KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to set HTTP Headers when using a Web Area in a 4D v13
PRODUCT: 4D | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: May 3, 2013

The 4D Web Area does not allow you to directly manipulate the HTTP Headers. However just because the command does not exist does not mean it cannot be done.

4D v13 introduced the HTTP REQUEST and HTTP GET commands which allow the devloper to set the HTTP Headers per request. When these commands are combined with the 4D Web Area, the doors open for what can be accomplished within the 4D Web Area. Here is a high level approach for displaying a page in a 4D Web Area that utilized custom HTTP Headers for the page rendering:

Define HTTP Headers within arrays
Use HTTP REQUEST command with header arrays
Get Response (content) into a variable
Display Response (content) using WA SET CONTENTS

Here is the above listed high level approach implemented in 4D code:

// declare variables
ARRAY TEXT(headerNames;3)
ARRAY TEXT(headerValues;3)
C_TEXT($body_t;response;headerTestURL_t)

// define HTTP Headers
headerNames{1}:="Accept-Encoding"
headerValues{1}:="gzip, deflate"
headerNames{2}:="Accept-Language"
headerValues{2}:="en-US"
headerNames{3}:="User-Agent"
headerValues{3}:="4D Web Area v13.2"

// prepare for HTTP Request
headerTestURL_t:="https://www.xhaus.com/headers"
HTTP Request(HTTP GET Method;headerTestURL_t;$body_t;response;headerNames;headerValues)

// display the response within the Web Area named "WA"
WA SET PAGE CONTENT(*;"WA";response;"file:///")