rq.sendRequest method lets you send an HTTP request from inside a script and read its response. Use it to fetch a token before the main request runs, call a second endpoint after a response arrives, or poll a status URL. It is available in both pre-request and post-response scripts.
Calling rq.sendRequest
You can callrq.sendRequest in two styles. Both send the same request.
Promise style (recommended):
null on success), the second is the response.
Request input
The first argument is either a URL string or a request configuration object.URL string
GET request.
Configuration object
url(string, required): The request URL.method(string, optional): The HTTP method. Defaults toGET.header(object or array, optional): Request headers. Use a plain object ({ "Header-Name": "value" }) or an array of rows ([{ key, value, disabled }]). The field name isheader, singular.body(object, optional): The request body. See Body modes.
Body modes
Thebody object has a mode that selects how the body is sent. Two modes are supported.
Raw
Sends the body exactly as you provide it. Set theContent-Type header yourself.
URL-encoded
Sends form fields asapplication/x-www-form-urlencoded. Requestly sets that Content-Type for you unless you set one yourself. Rows marked disabled: true are skipped.
Multipart form-data and file-upload bodies are not supported by
rq.sendRequest. Scripts run in a sandbox with no access to your file system, so a body cannot read a file from disk.Response
The response object passed to your callback (and resolved by the promise) has these members:code(number): The numeric HTTP status, for example200.status(string): The HTTP status text, for example"OK".headers: The response headers. Read one withheaders.get("content-type")(case-insensitive) orheaders["content-type"].responseTime(number): The round-trip time in milliseconds.json(): Parses the response body as JSON and returns it. Throws if the body is not valid JSON.text(): Returns the raw response body as a string.
Error handling
An error is reported two ways at once: the promise rejects, and the callback receives it as the first argument. Handle whichever style you are using.- Invalid arguments: the configuration has no usable
url. The request is never sent. - Network error: the request could not reach the server (for example DNS failure, connection refused, or a TLS problem).
404 or 500 is not treated as an error. The promise resolves and the callback receives the response normally. Inspect res.code to decide how to handle the status:
Always
await the promise or attach a .catch() (or pass a callback). A request that is never awaited may have its error go unreported if the script finishes first.
