class Httprequest (View source)

HTTP requests library

Methods

__construct(string $address = false, bool $curl = true)

Class constructor

__destruct()

Class destructor

setHost(string $address)

Set remote host address

setCurl(bool $mode = true)

Force lib to use curl (default if available) or stream

setAuth(string $method, string $user, string $pass = null)

Set http authentication

setUserAgent(string $ua)

Set user agent for request

setTimeout(int $sec)

Set connection timeout

setHttpVersion(string $ver)

Set http version (1.0/1.1)

setContentType(string $type)

Set http content type

setPort(integer $port)

Set TCP port to connect to

setHttpMethod(string $method)

Set HTTP method to use

setIgnoreErrors(boolean $ignore = true)

Set whether or not to ignore errors

setProxy(string $address, string $user = null, string $pass = null)

Set HTTP method to use

setHeader(string $header, string $value = NULL)

Set header component

unsetHeader(string $header)

Unset header component

array
getHeaders()

Get the whole headers array

array
getReceivedHeaders()

Get received headers

integer
getHttpStatusCode()

Get received headers

mixed
getChannel()

Get transport channel (curl channel or stream context)

string
send($data = null)

Init transport and send data to the remote host.

string
get()

Init transport and get remote content

reset()

Reset the data channel for new request

Details

final __construct(string $address = false, bool $curl = true)

Class constructor

Parameters

string $address Remote host address
bool $curl Use curl (true) or stream (false)

Exceptions

HttpException

final __destruct()

Class destructor

final Httprequest setHost(string $address)

Set remote host address

Parameters

string $address Remote host address

Return Value

Httprequest

Exceptions

HttpException

final Httprequest setCurl(bool $mode = true)

Force lib to use curl (default if available) or stream

Parameters

bool $mode Use curl (true) or stream (false)

Return Value

Httprequest

final Httprequest setAuth(string $method, string $user, string $pass = null)

Set http authentication

Parameters

string $method Auth method (BASIC or NTLM)
string $user Username to use
string $pass User password

Return Value

Httprequest

Exceptions

HttpException

final Httprequest setUserAgent(string $ua)

Set user agent for request

Parameters

string $ua User Agent

Return Value

Httprequest

Exceptions

HttpException

final Httprequest setTimeout(int $sec)

Set connection timeout

Parameters

int $sec Timeout to wait for (in second)

Return Value

Httprequest

final Httprequest setHttpVersion(string $ver)

Set http version (1.0/1.1)

Parameters

string $ver 1.0 or 1.1

Return Value

Httprequest

final Httprequest setContentType(string $type)

Set http content type

Parameters

string $type

Return Value

Httprequest

Exceptions

HttpException

final Httprequest setPort(integer $port)

Set TCP port to connect to

Parameters

integer $port TCP port (default 80)

Return Value

Httprequest

final Httprequest setHttpMethod(string $method)

Set HTTP method to use

Parameters

string $method HTTP METHOD

Return Value

Httprequest

Exceptions

HttpException

final Httprequest setIgnoreErrors(boolean $ignore = true)

Set whether or not to ignore errors

Parameters

boolean $ignore Should stream ignore errors

Return Value

Httprequest

final Httprequest setProxy(string $address, string $user = null, string $pass = null)

Set HTTP method to use

Parameters

string $address Proxy URL or IP address
string $user (optional) User name for proy auth
string $pass (optional) User password for proxy auth

Return Value

Httprequest

Exceptions

HttpException

final Httprequest setHeader(string $header, string $value = NULL)

Set header component

Parameters

string $header Header name
string $value Header content (optional)

Return Value

Httprequest

final Httprequest unsetHeader(string $header)

Unset header component

Parameters

string $header Header name

Return Value

Httprequest

final array getHeaders()

Get the whole headers array

Return Value

array

final array getReceivedHeaders()

Get received headers

Return Value

array

final integer getHttpStatusCode()

Get received headers

Return Value

integer

final mixed getChannel()

Get transport channel (curl channel or stream context)

Return Value

mixed

string send($data = null)

Init transport and send data to the remote host.

Parameters

$data

Return Value

string

Exceptions

HttpException

string get()

Init transport and get remote content

Return Value

string

Exceptions

HttpException

final reset()

Reset the data channel for new request