Script.Util.HttpRequest

Performs an HTTP request against a specified URL. When you use this request handler’s send() method, it returns a Script.Util.HttpResponse object that contains the response data. Unlike the HTTP request functions in the SSJS Core and Platform libraries, you can use this handler to perform other types of HTTP requests, such as PUT, PATCH, or DELETE.

This request handler only works with HTTP on port 80 and HTTPS on port 443.

OrdinalTypeDescription
1StringRequired. The URL to send the HTTP request to.

The Script.Util.HttpRequest request handler has the methods listed in this table.

MethodDescription
clearHeaders()Removes all custom headers for the request.
removeHeader(String)Removes a specific custom header from the request.
send()Sends the request and returns a Script.Util.HttpRequest object. This method times out after 30 seconds.
setHeader(String, String)Adds a custom headers to the request. If you use this method to specify a header, content caching is disabled.

The value of the host header is always set to the domain of the URL that the request was sent to, and the value of the content-length header is always set to the number of bytes of data in the request body. You can’t use the setHeader() method to modify the values of either of these headers.

The Script.Util.HttpRequest request handler has the configuration properties listed in this table.

PropertyTypeDescription
contentTypeStringThe content type to use in requests, such as application/json or application/x-www-form-urlencoded.
encodingStringThe content encoding to use in requests, such as UTF-8.
methodStringThe HTTP verb to use in the request. Possible values:
  • GET
  • DELETE
  • HEAD
  • OPTIONS
  • PATCH
  • POST
  • PUT
postDataStringThe request body. This property is required for POST requests.

To use this request handler, initialize it and provide the destination URL. Next, specify the properties of the request, such as the HTTP method to use and the content of the request body. This example issues a PUT request to a destination server.

The example outputs the full body of the response received from the server.