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

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

Function Properties

The function has the properties listed in this table.

Ordinal Type Description
1 String Required. The URL to send data to.
2 String Required. The content-type header value to use in the request.
3 Object Required. The payload of the POST request.
4 Array Required. An array of header names to include in the POST request.
5 Array Required. An array of header values to include in the POST request.
6 Array Required. 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.

<script runat="server">
  var url = "https://example.com";
  var contentTypeHeader = "application/json";
  var requestPayload = '{"name","value"}';
  var headerNames = ["header1", "header2"];
  var headerValues = ["value1", "value2"];

  var response = [0];

  try {
    var statusCode = Platform.Function.HTTPPost(
        url,
        contentTypeHeader,
        requestPayload,
        headerNames,
        headerValues,
        response
    );

    if (statusCode == 200) {
      Platform.Response.Write(response[0]);
    }
  } catch(e) {
    Platform.Response.Write(Platform.Function.Stringify(e));
  }
</script>

See Also