Documentation

HttpReq
in package

Simple HTTP(s) request wrapper

Table of Contents

Constants

METHOD_GET  : mixed = 'GET'
METHOD_POST  : mixed = 'POST'
METHOD_PUT  : mixed = 'PUT'

Properties

$http_headers  : mixed
$http_info  : mixed
$http_status  : mixed

Methods

get()  : string
Make a simple GET request.
getLastreqHeaders()  : array<string|int, mixed>
Return headers of the last request
getLastreqInfo()  : array<string|int, mixed>
Return info of the last request
getLastreqStatus()  : int
Return the http status code ofthe last request
post()  : string
Make a simple POST request, with optional data If you need more control, use @see HttpReq::req
req()  : string|false
Make a HTTP request. Returns the response content.
reqAdvanced()  : string
Performs a request while permitting advanced cURL options to be specified.
buildHeadersString()  : string
Converts an array of headers into a \r\n-delimeted string
reqCurl()  : mixed
Sends a HTTP request using cURL.
reqFopen()  : mixed
Sends a HTTP request using fopen (i.e. file_get_contents)

Constants

METHOD_GET

public mixed METHOD_GET = 'GET'

METHOD_POST

public mixed METHOD_POST = 'POST'

METHOD_PUT

public mixed METHOD_PUT = 'PUT'

Properties

$http_headers

private static mixed $http_headers

$http_info

private static mixed $http_info

$http_status

private static mixed $http_status

Methods

get()

Make a simple GET request.

public static get(string $url) : string

If you need more control, use @see HttpReq::req

Parameters
$url : string

The URL to fetch

Return values
string —

Response data

getLastreqHeaders()

Return headers of the last request

public static getLastreqHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLastreqInfo()

Return info of the last request

public static getLastreqInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLastreqStatus()

Return the http status code ofthe last request

public static getLastreqStatus() : int
Return values
int —

The HTTP status code of the last request

post()

Make a simple POST request, with optional data If you need more control, use @see HttpReq::req

public static post(string $url[, array<string|int, mixed> $data = null ]) : string
Parameters
$url : string

The URL to send a POST request to

$data : array<string|int, mixed> = null

The POST data

Return values
string —

Response data

req()

Make a HTTP request. Returns the response content.

public static req(string $url, array<string|int, mixed> $opts[, string|array<string|int, mixed>|null $data = null ]) : string|false

The request options array accepts the following keys: method The HTTP method to use ('GET', 'POST') headers An array of headers; see ::buildHeadersString for format information

Parameters
$url : string

The URL to request.

$opts : array<string|int, mixed>

Request options array.

$data : string|array<string|int, mixed>|null = null

Request data, for POST requests.

Return values
string|false

reqAdvanced()

Performs a request while permitting advanced cURL options to be specified.

public static reqAdvanced(string $url, string $method[, string|array<string|int, mixed> $post_data = null ][, array<string|int, mixed> $curl_options = [] ]) : string

Essentially just a wrapper around cURL that has some sane options set by default; e.g. return transfer, no return headers, SSL configured, proxy settings.

Parameters
$url : string

The URL to fetch.

$method : string

The HTTP request method, e.g. 'POST', 'GET', etc. Case sensitive.

$post_data : string|array<string|int, mixed> = null

Data for a POST/PUT request, other request types should leave this null.

$curl_options : array<string|int, mixed> = []

Any options for cURL; these will override any default.

Tags
throws
Exception

If a cURL error is encountered.

Return values
string —

The response data (if any)

buildHeadersString()

Converts an array of headers into a \r\n-delimeted string

protected static buildHeadersString(string|array<string|int, mixed> $headers) : string

Accepts three formats:

  • Strings will be passed through as is.
  • Arrays of strings (with numeric keys) will be used as-is
  • Arrays of strings (with string keys) will be joined using : to separate the key and value. Also, values containing quotes or spaces will be quoted.
Parameters
$headers : string|array<string|int, mixed>

The headers to process

Return values
string —

HTTP headers

reqCurl()

Sends a HTTP request using cURL.

protected static reqCurl(mixed $url, array<string|int, mixed> $opts[, mixed $data = '' ]) : mixed
Parameters
$url : mixed
$opts : array<string|int, mixed>
$data : mixed = ''

reqFopen()

Sends a HTTP request using fopen (i.e. file_get_contents)

protected static reqFopen(mixed $url, array<string|int, mixed> $opts[, mixed $data = null ]) : mixed
Parameters
$url : mixed
$opts : array<string|int, mixed>
$data : mixed = null
On this page

Search results