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.
| 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: <ul><li>0 - OK</li><li>1 - Empty URL</li><li>2 - Call failed</li><li>3 - Call succeeded with empty content</li></ul> |
statusCode |
Number | The 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.
<script runat="server">
/* Specify the request body as a string */
var requestBody = '{"email": "ralph.vasquez@example.com","customerKey": "b714fdda-4a05-483c-972c-e04c9452b3aa"}';
try {
/* Initialize the request handler */
var request = new Script.Util.HttpRequest("https://www.example.com/put");
/* Configure the request properties */
request.method = "PUT";
request.encoding = "UTF-8";
request.postData = requestBody;
request.contentType = "application/json";
/* Send the request */
var response = request.send();
/* Get the properties of the Script.Util.HttpResponse object */
var responseData = {
"Content": String(response.content),
"ContentType": response.contentType,
"Encoding": response.encoding,
"Headers": response.headers,
"ReturnStatus": response.returnStatus,
"StatusCode": response.statusCode
};
/* Output the response data */
for (var i in responseData) {
Platform.Response.Write(i + ": " + responseData[i] + "<br/>")
}
} catch(e) {
Platform.Response.Write(Platform.Function.Stringify(e));
}
</script>