KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to Send Data with URL Encoded Content-Type HTTP Request
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: July 12, 2021

When making an HTTP request and specifying the content-type as "application/x-www-form-urlencoded" (URL encoded) in the HTTP header, the body content of the request must be formatted and sent as text.

The body must have the key/value pair formatted as a string like below. The data is encoded in key/value tuples with the "&" (ampersand) separating the tuples and "=" (equal) between the key/value pair:

  • "key=value&key1=value1"

For example, if the data to send in the HTTP request contains:
  • username: Admin

  • password: MyPass

It must be formated in the body as:
  • "username=Admin&password=MyPass"

The URL Encoded HTTP request would look like this.
ARRAY TEXT($header_name; 0)
ARRAY TEXT($header_value; 0)
C_TEXT($content)
C_LONGINT($HTTPstatus)
C_VARIANT($response)

//Sets URL Encoded Content-Type in HTTP Header
APPEND TO ARRAY($header_name; "Content-Type")
APPEND TO ARRAY($header_value; "application/x-www-form-urlencoded")

//Formatted Body Content of the HTTP request
$content:="username=Admin&password=MyPass"

$HTTPstatus:=HTTP Request(HTTP POST method; "example.com"; $content; $response; $header_name; $header_value)