AMPscript
Platform.Function.HTTPGet()
Platform.Function.HTTPPost()
Script.Util.HttpGet
Script.Util.HttpResponse
Script.Util.HttpRequest
Validate Your Server-Side JavaScript using WSProxy
An object that contains information about an HTTP request. This object is returned by calling the send() method of the Script.Util.HttpGet and Script.Util.HttpRequest request handlers.
The Script.Util.HttpResponse object has the properties listed in this table.
| Property | Type | Description |
|---|---|---|
content | String | The content body returned in the response. |
contentType | String | The content type returned in the response. |
encoding | String | The type of encoding returned in the response. |
headers | Object | An object that contains the response headers returned in the response. |
returnStatus | Number | A value that indicates the status of the response. Possible values:
|
statusCode | Number | The HTTP status code that the request returned, such as 200 or 404. |
This example shows how to reference the properties of a Script.Util.HttpResponse object returned by the Script.Util.HttpRequest() request handler.
1<script runat="server">
2 /* Specify the request body as a string */
3 var requestBody = '{"email": "ralph.vasquez@example.com","customerKey": "b714fdda-4a05-483c-972c-e04c9452b3aa"}';
4
5 try {
6 /* Initialize the request handler */
7 var request = new Script.Util.HttpRequest("https://www.example.com/put");
8
9 /* Configure the request properties */
10 request.method = "PUT";
11 request.encoding = "UTF-8";
12 request.postData = requestBody;
13 request.contentType = "application/json";
14
15 /* Send the request */
16 var response = request.send();
17
18 /* Get the properties of the Script.Util.HttpResponse object */
19 var responseData = {
20 "Content": String(response.content),
21 "ContentType": response.contentType,
22 "Encoding": response.encoding,
23 "Headers": response.headers,
24 "ReturnStatus": response.returnStatus,
25 "StatusCode": response.statusCode
26 };
27
28 /* Output the response data */
29 for (var i in responseData) {
30 Platform.Response.Write(i + ": " + responseData[i] + "<br/>")
31 }
32 } catch(e) {
33 Platform.Response.Write(Platform.Function.Stringify(e));
34 }
35</script>