HTTP.Get()

Performs an HTTP GET by using the provided name and value pairs against the passed URL, and it returns a JSON object that contains a status value and the HTTP response. You can include multiple pairs of header names and values. This function only works with HTTP on port 80 and HTTPS on port 443.

Syntax

HTTP.Get(1, 2, 3)

Properties

The HTTP.Get() function has the properties listed in this table.

Ordinal Type Description
1 String Required. The destination URL for the HTTP GET request.
2 Array An array of header names to include in the request.
3 Array An array of header values to include in the request.
<!--[BM 2/13/25] This section doesn't seem relevant to the function. Commenting it out in case we need to restore it later. Marketing Cloud Engagement recognizes any character set returned in the HTTP headers by setting the appropriate `Content-Type` header. For example, you can use a UTF-8 encoded HTML file by including `Content-Type: text/html; charset=utf-8` in the header. If you don’t specify the encoding in the header, data is returned using the WindowsCodePage 1252 character set. To change the default content type, contact Salesforce Customer Support. -->

Usage

This sample code performs an HTTP GET and outputs the response object.

<script runat="server">
  Platform.Load('Core','1');

  var url = "https://example.com/forms/myForm.html";
  var headerNames = ["MyTestHeader1", "MyTestHeader2"];
  var headerValues = ["MyTestValue1", "MyTestValue2"];

  try {
    var response = HTTP.Get(url, headerNames, headerValues);
    Write(Stringify(response));
  } catch(e) {
    Write(Stringify(e));
  }
</script>

The response is a JSON object that contains a numeric status value and the response body of the GET request.

{
  "Status": 0,
  "Content": "{
    \"args\": {},
    \"headers\": {
      \"Host\": \"example.com\",
      \"Mytestheader1\": \"MyTestValue1\",
      \"Mytestheader2\": \"MyTestValue2\",
      \"X-Amzn-Trace-Id\": \"Root=1-67ae4eb9-4b57ee616f927d773ff4f5be\"
    },
    \"origin\": \"203.0.113.1\",
    \"url\": \"https://example.com/forms/myForm.html\"
  }"
}

See Also