Platform.Function.HTTPPost()

Posts content to the specified URL. This function only works with HTTP on port 80 and HTTPS on port 443. Non-standard port assignments cause this function to fail. Marketing Cloud Engagement honors any character sets specified in the content-type header. For example, you can use a UTF-8 encoded HTML file with content-type: text/html; charset=utf-8 included in the header. If the header doesn’t specify the encoding, the application assumes that all returned data uses WindowsCodePage 1252 the character set. The timeout value for this function is 30 seconds.

Syntax 

1Platform.Function.HTTPPost(1, 2, 3, 4, 5, 6)

Function Properties 

The function has the properties listed in this table.

OrdinalTypeDescription
1StringRequired. The URL to send data to.
2StringRequired. The content-type header value to use in the request.
3ObjectRequired. The payload of the POST request.
4ArrayRequired. An array of header names to include in the POST request.
5ArrayRequired. An array of header values to include in the POST request.
6ArrayRequired. An array that holds the response data for the POST request.

Return Values 

The function returns a numeric HTTP status code. For example, if the request is successfully received, the return value is 200.

Usage 

This example sends a simple JSON object to https://example.com by issuing a POST request.

1<script runat="server">
2  var url = "https://example.com";
3  var contentTypeHeader = "application/json";
4  var requestPayload = '{"name","value"}';
5  var headerNames = ["header1", "header2"];
6  var headerValues = ["value1", "value2"];
7
8  var response = [0];
9
10  try {
11    var statusCode = Platform.Function.HTTPPost(
12        url,
13        contentTypeHeader,
14        requestPayload,
15        headerNames,
16        headerValues,
17        response
18    );
19
20    if (statusCode == 200) {
21      Platform.Response.Write(response[0]);
22    }
23  } catch(e) {
24    Platform.Response.Write(Platform.Function.Stringify(e));
25  }
26</script>

See Also