HTTPGet

This function retrieves, or ‘gets’ content from a defined publicly accessible URL.

NOTE: The function only works with HTTP content on TCP/IP port 80 and HTTPS on port 443. Basic access authentication in URLs is not supported (for example, https://username:[email protected]://domain.com).

Arguments

HTTPGet(1,2,3,4)

Ordinal Type Required Description
1 String True URL used to retrieve content
2 String False Whether the process continues on an error. A value of true ignores errors in the process. It defaults to false if not specified.
3 String False Defines whether the function allows empty content. A value of 0 permits empty content. A value of 1 returns an error. A value of 2 skips sending an email to the Subscriber (if the function is used in an email).
4 String False Outputs the function status. A value of 0 indicates the status is successful, -1 indicates a 404 error (URL not found), -2 indicates an HTTP request error (the server did not return a 2xx status code) and -3 indicates empty content.

Example 1

The following example retrieves HTML content from an external URL and displays it in an email, web page or message.

%%[

var @getRequest
set @getRequest = TreatAsContent(HTTPGet("https://httpbin.org/html"))

]%%
%%=v(@getRequest)=%%

Output

The request will return HTML content from the source URL.

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
      <h1>Herman Melville - Moby-Dick</h1>
      <div>
        <p>
          Availing himself of the mild, summer-cool weather that now reigned in these latitudes, and in preparation for the peculiarly active pursuits shortly to be anticipated, Perth, the begrimed, blistered old blacksmith, had not removed his portable forge to the hold again, after concluding his contributory work for Ahab's leg...
        </p>
      </div>
  </body>
</html>

Example 2


Not a subscriber? Subscribe now.

Example 3


Not a subscriber? Subscribe now.