Platform.Function.HTTPGet()

Retrieves information from a URL by issuing an HTTP GET request. This function only works with HTTP on port 80 and HTTPS on port 443. The function times out after 30 seconds.

Syntax

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

Properties

The function has the properties listed in this table.

Ordinal Type Description
1 String Required. The URL to retrieve content from.
2 Boolean Required. Indicates whether the request continues if an error occurs during the process. If the value is true, the request terminates if an error occurs. If the value is false, the request continues if an error occurs.
3 Numeric Indicates how the function handles a URL that returns empty content. A value of 0 allows empty content. A value of 1 returns an error. A value of 2 skips the subscriber.
4 Array Required. An array of header names to include in the GET request.
5 Array Required. An array of header values that correspond to the header names defined in 4.
6 String The name of a variable that stores the status code for the request.

Return Values

This function returns a numeric status.

  • A value of 0 indicates that the request completed successfully.
  • A value of -1 indicates that the URL wasn’t found.
  • A value of -2 indicates that error occurred in the HTTP request.
  • A value of -3 indicates that the function completed successfully but didn’t return any content.

Usage

This example retrieves data from a URL by using a GET request.

<script runat="server">
  var status = [0];

  try {
    var content = Platform.Function.HTTPGet(
        "https://example.com",
        false,
        0,
        ["x-request-id"],
        ["sampleValue"],
        status);
    if(status[0] == 0) {
      Platform.Response.Write(content);
    };
  } catch(e) {
    Platform.Response.Write(Platform.Function.Stringify(e));
  };
</script>

See Also