Cookies
Get, set, and clear cookies for the request host resolved at send start. Available in pre- and post-request scripts. The host comes from the request URL before scripts run; changing hc.request.url mid-script does not retarget this bag.
Cookie changes persist to the cookie jar when the send completes.
hc.cookies.clear(name)
Available since v2.0.0
Signature:(name: string) => void
Removes a cookie by name for the request host. Persisted to the jar when the send completes.
hc.cookies.clear("session_id");hc.cookies.get(name)
Available since v2.0.0
Signature:(name: string) => string | undefined
Returns the cookie value for name (case-insensitive). Returns undefined when the cookie is absent or was cleared during this send.
var session = hc.cookies.get("session_id");hc.cookies.set(name, value)
Available since v2.0.0
Signature:(name: string, value: string) => void
Sets a cookie for the request host. Values are coerced to strings. New cookies are enabled by default.
hc.cookies.set("session_id", "abc123");