KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: HTTP Post: Don't forget the Content-Length
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: May 6, 2012

When executing an HTTP Post, it is common for the web server that is on the receiving end to require that the content length be sent. Content length being the HTTP header field "Content-Length".

If the "Content-Length" header is not included with an HTTP Post, then a web server can respond with status 400 (bad request) or status 411 (length required).

Taking this into account, here is an example of how to make an HTTP Post and include the "Content-length" header.

This specific example would be equivalent to filling out input fields in an HTML form on a web page and clicking on a "Submit" button.

ARRAY TEXT($headers_at;0)
ARRAY TEXT($values_at;0)
C_TEXT($url_t;$body_t;$response_t)
C_LONGINT($error_l)

$url_t:="http://www.sciencemadesimple.net/length.php"

$body_t:="quantityin=100&"+\
"from=meters&"+\
"to=feet&"+\
"decimals=s2"

APPEND TO ARRAY($headers_at;"Content-Length")
APPEND TO ARRAY($values_at;String(Length($body_t)))
APPEND TO ARRAY($headers_at;"Content-Type")
APPEND TO ARRAY($values_at;"application/x-www-form-urlencoded")

$error_l:=HTTP Request(HTTP POST Method;$url_t;$body_t;$response_t;\
    $headers_at;$values_at)