Skip to main content
Version: 1.23

RequestOptions

The RequestOptions allows to create form data to be sent via APIRequestContext.

context.request().post(
"https://example.com/submit",
RequestOptions.create()
.setQueryParam("page", 1)
.setData("My data"));

RequestOptions.create()

Creates new instance of RequestOptions.

RequestOptions.setData(data)

  • data <String|byte[]|Object> Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and content-type header will be set to application/json if not explicitly set. Otherwise the content-type header will be set to application/octet-stream if not explicitly set.#
  • returns: <RequestOptions>#

Sets the request's post data.

RequestOptions.setFailOnStatusCode(failOnStatusCode)

  • failOnStatusCode <boolean> Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.#
  • returns: <RequestOptions>#

RequestOptions.setForm(form)

  • form <FormData> Form data to be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body.#
  • returns: <RequestOptions>#

Provides FormData object that will be serialized as html form using application/x-www-form-urlencoded encoding and sent as this request body. If this parameter is specified content-type header will be set to application/x-www-form-urlencoded unless explicitly provided.

RequestOptions.setHeader(name, value)

Sets an HTTP header to the request.

RequestOptions.setIgnoreHTTPSErrors(ignoreHTTPSErrors)

  • ignoreHTTPSErrors <boolean> Whether to ignore HTTPS errors when sending network requests.#
  • returns: <RequestOptions>#

RequestOptions.setMethod(method)

Changes the request method (e.g. PUT or POST).

RequestOptions.setMultipart(form)

  • form <FormData> Form data to be serialized as html form using multipart/form-data encoding and sent as this request body.#
  • returns: <RequestOptions>#

Provides FormData object that will be serialized as html form using multipart/form-data encoding and sent as this request body. If this parameter is specified content-type header will be set to multipart/form-data unless explicitly provided.

RequestOptions.setQueryParam(name, value)

Adds a query parameter to the request URL.

RequestOptions.setTimeout(timeout)

Sets request timeout in milliseconds. Defaults to 30000 (30 seconds). Pass 0 to disable timeout.