Script.Util.HttpResponse

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.

Properties 

The Script.Util.HttpResponse object has the properties listed in this table.

PropertyTypeDescription
contentStringThe content body returned in the response.
contentTypeStringThe content type returned in the response.
encodingStringThe type of encoding returned in the response.
headersObjectAn object that contains the response headers returned in the response.
returnStatusNumberA value that indicates the status of the response. Possible values:
  • 0 - OK
  • 1 - Empty URL
  • 2 - Call failed
  • 3 - Call succeeded with empty content
statusCodeNumberThe HTTP status code that the request returned, such as 200 or 404.

Usage 

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>

See Also