fetch()
Send one request in a throwaway session.
import { fetch, ClientIdentifier } from "node-tls-client";
const res = await fetch("https://httpbin.org/get", {
options: { clientIdentifier: ClientIdentifier.firefox_148, timeout: 5000 },
});fetch(url: string, options?: fetchOptions): Promise<Response>Creates a Session from options.options, sends one request, closes the session and resolves with the Response. initTLS() must have been called first.
Use it when each request needs different session settings (a different timeout, profile or insecureSkipVerify). For several requests to the same site, use a Session: it keeps cookies and connections between requests, and fetch() doesn't.
methoddefaults to"GET"and is case-insensitive. Anything other thanGET,POST,PUT,DELETE,PATCH,OPTIONSorHEADrejects with aTlsClientError.- Errors are rethrown as
TlsClientError. - The session is closed even when the request fails.
fetchOptions
| Field | Type | Description |
|---|---|---|
method? | Methods | Request method. |
headers? | HeaderInput | The headers for the request. |
body? | string | Buffer | Uint8Array | null | The body of the request (string, or Buffer for binary payloads). |
followRedirects? | boolean | Whether to follow redirects. |
proxy? | string | The proxy server to use for the request. |
isRotatingProxy? | boolean | Whether proxy is rotating proxy or not. |
cookies? | Record<string, string | number> | Cookies for the request. |
options? | SessionOptions | Additional session options. |