class HttpClient (View source)

Methods

__construct(string|null $base_url = null)

HttpClient Constructor.

void
setBaseUrl(string $url)

Set the base url

get(string $url, array $data = [])

Make GET request

post(string $url, array $data = [])

Make POST request

put(string $url, array $data = [])

Make PUT request

delete(string $url, array $data = [])

Make DELETE request

patch(string $url, array $data = [])

Make PATCH request

head(string $url, array $data = [])

Make HEAD request (retrieves headers only, no body)

options(string $url)

Make OPTIONS request (retrieves allowed HTTP methods)

addAttach(string|array $attach)

Attach file(s) to the request

setUserAgent(string $user_agent)

Set the User-Agent header

acceptJson() deprecated

Configure client to accept and send JSON data

withJson()

Configure client to accept and send JSON data

withHeaders(array $headers)

Add custom HTTP headers

bool
hasHeader(string $key, string $value)

Check if header exists

auth(string $username, string $password)

Set HTTP authentication credentials

basicAuth(string $key, string $secret)

Set Basic HTTP authentication

bearerAuth(string $token)

Set Bearer token authentication

timeout(int $seconds)

Set the maximum time the request is allowed to take

connectTimeout(int $seconds)

Set the maximum time to wait for a connection

disableSslVerification()

Disable SSL certificate verification

Details

__construct(string|null $base_url = null)

HttpClient Constructor.

Parameters

string|null $base_url

void setBaseUrl(string $url)

Set the base url

Parameters

string $url

Return Value

void

Response get(string $url, array $data = [])

Make GET request

Parameters

string $url
array $data

Return Value

Response

Exceptions

Exception

Response post(string $url, array $data = [])

Make POST request

Parameters

string $url
array $data

Return Value

Response

Exceptions

Exception

Response put(string $url, array $data = [])

Make PUT request

Parameters

string $url
array $data

Return Value

Response

Exceptions

Exception

Response delete(string $url, array $data = [])

Make DELETE request

Parameters

string $url
array $data

Return Value

Response

Exceptions

Exception

Response patch(string $url, array $data = [])

Make PATCH request

Parameters

string $url
array $data

Return Value

Response

Exceptions

Exception

Response head(string $url, array $data = [])

Make HEAD request (retrieves headers only, no body)

Parameters

string $url
array $data

Return Value

Response

Exceptions

Exception

Response options(string $url)

Make OPTIONS request (retrieves allowed HTTP methods)

Parameters

string $url

Return Value

Response

Exceptions

Exception

HttpClient addAttach(string|array $attach)

Attach file(s) to the request

Parameters

string|array $attach

Return Value

HttpClient

HttpClient setUserAgent(string $user_agent)

Set the User-Agent header

Parameters

string $user_agent

Return Value

HttpClient

HttpClient acceptJson() deprecated

deprecated 5.2.99

Configure client to accept and send JSON data

Return Value

HttpClient

HttpClient withJson()

Configure client to accept and send JSON data

Return Value

HttpClient

HttpClient withHeaders(array $headers)

Add custom HTTP headers

Parameters

array $headers

Return Value

HttpClient

bool hasHeader(string $key, string $value)

Check if header exists

Parameters

string $key
string $value

Return Value

bool

HttpClient auth(string $username, string $password)

Set HTTP authentication credentials

Parameters

string $username
string $password

Return Value

HttpClient

HttpClient basicAuth(string $key, string $secret)

Set Basic HTTP authentication

Parameters

string $key
string $secret

Return Value

HttpClient

HttpClient bearerAuth(string $token)

Set Bearer token authentication

Parameters

string $token

Return Value

HttpClient

HttpClient timeout(int $seconds)

Set the maximum time the request is allowed to take

Parameters

int $seconds

Return Value

HttpClient

HttpClient connectTimeout(int $seconds)

Set the maximum time to wait for a connection

Parameters

int $seconds

Return Value

HttpClient

HttpClient disableSslVerification()

Disable SSL certificate verification

Warning: This should only be used in development environments

Return Value

HttpClient