HTTP & JSON httpAddHeader

$httpAddHeader[]

Adds a custom HTTP header to all subsequent HTTP requests made with $httpGet, $httpPost, $httpPut, $httpPatch, or $httpDelete

Syntax
$httpAddHeader[name;value]

Parameters

Parameter Type Required Default Description
name string check_circle Required The HTTP header name (e.g., Content-Type, Authorization, Accept)
value string check_circle Required The header value to set

Return Value

void

This function does not return a value. It modifies internal request state for subsequent HTTP calls.

$httpAddHeader sets a custom HTTP header that is included on all subsequent HTTP requests until cleared or overwritten. Call it multiple times to set multiple headers. Headers are applied to every request made via $httpGet, $httpPost, $httpPut, $httpPatch, and $httpDelete. Common use cases include setting Content-Type for JSON APIs, Authorization for authenticated endpoints, and custom headers for API-specific requirements. Headers persist for the duration of the command execution context.

Examples

Set JSON content type

$httpAddHeader[Content-Type;application/json]
$httpAddHeader[Accept;application/json]
$httpPost[https://jsonplaceholder.typicode.com/posts;{"title":"Test"}]
$description[Created: $httpResult[id]]

Authenticated API request

$httpAddHeader[Authorization;Bearer sk-abc123xyz]
$httpGet[https://api.example.com/v1/me]
$description[User: $httpResult[username] — Status: $httpStatus]

Multiple headers for a POST

$httpAddHeader[Content-Type;application/json]
$httpAddHeader[Authorization;Bearer my-secret-token]
$httpAddHeader[X-Custom-Header;custom-value]
$httpPost[https://httpbin.org/post;{"key":"value"}]
Response headers echoed: $httpResult[headers;X-Custom-Header]