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

addAttach(string|array $attach)

Attach file(s) to the request

setUserAgent(string $user_agent)

Set the User-Agent header

acceptJson()

Configure client to accept and send JSON data

withHeaders(array $headers)

Add custom HTTP headers

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

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()

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

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