Requests 2.0.11 API

Curl
in package
implements Transport

FinalYes

cURL HTTP transport

Table of Contents

Interfaces

Transport
Base HTTP transport

Constants

CURL_7_10_5  = 0x70a05
CURL_7_16_2  = 0x71002

Properties

$headers  : string
Raw HTTP data
$info  : array<string|int, mixed>
Information on the current request
$response_data  : string
Raw body data
$version  : int
cURL version number

Methods

__construct()  : mixed
Constructor
__destruct()  : mixed
Destructor
get_subrequest_handle()  : resource|CurlHandle
Get the cURL handle for use in a multi-request
process_response()  : string|false
Process a response
request()  : string
Perform a request
request_multiple()  : array<string|int, mixed>
Send multiple requests simultaneously
stream_body()  : int
Collect data as it's received
stream_headers()  : int
Collect the headers as they are received
test()  : bool
Self-test whether the transport can be used.

Constants

CURL_7_10_5

public mixed CURL_7_10_5 = 0x70a05

CURL_7_16_2

public mixed CURL_7_16_2 = 0x71002

Properties

$headers

Raw HTTP data

public string $headers = ''

$info

Information on the current request

public array<string|int, mixed> $info

cURL information array, see

$response_data

Raw body data

public string $response_data = ''

$version

cURL version number

public int $version

Methods

__construct()

Constructor

public __construct() : mixed

__destruct()

Destructor

public __destruct() : mixed

get_subrequest_handle()

Get the cURL handle for use in a multi-request

public & get_subrequest_handle(string $url, array<string|int, mixed> $headers, string|array<string|int, mixed> $data, array<string|int, mixed> $options) : resource|CurlHandle
Parameters
$url : string

URL to request

$headers : array<string|int, mixed>

Associative array of request headers

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

Data to send either as the POST body, or as parameters in the URL for a GET/HEAD

$options : array<string|int, mixed>

Request options, see Requests::response() for documentation

Return values
resource|CurlHandle

Subrequest's cURL handle

process_response()

Process a response

public process_response(string $response, array<string|int, mixed> $options) : string|false
Parameters
$response : string

Response data from the body

$options : array<string|int, mixed>

Request options

Tags
throws
Exception

If the request resulted in a cURL error.

Return values
string|false

HTTP response data including headers. False if non-blocking.

request()

Perform a request

public request(string|Stringable $url[, array<string|int, mixed> $headers = [] ][, string|array<string|int, mixed> $data = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
$url : string|Stringable

URL to request

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

Associative array of request headers

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

Data to send either as the POST body, or as parameters in the URL for a GET/HEAD

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

Request options, see Requests::response() for documentation

Tags
throws
InvalidArgument

When the passed $url argument is not a string or Stringable.

throws
InvalidArgument

When the passed $headers argument is not an array.

throws
InvalidArgument

When the passed $data parameter is not an array or string.

throws
InvalidArgument

When the passed $options argument is not an array.

throws
Exception

On a cURL error (curlerror)

Return values
string

Raw HTTP result

request_multiple()

Send multiple requests simultaneously

public request_multiple(array<string|int, mixed> $requests, array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$requests : array<string|int, mixed>

Request data

$options : array<string|int, mixed>

Global options

Tags
throws
InvalidArgument

When the passed $requests argument is not an array or iterable object with array access.

throws
InvalidArgument

When the passed $options argument is not an array.

Return values
array<string|int, mixed>

Array of \WpOrg\Requests\Response objects (may contain \WpOrg\Requests\Exception or string responses as well)

stream_body()

Collect data as it's received

public stream_body(resource|CurlHandle $handle, string $data) : int
Parameters
$handle : resource|CurlHandle

cURL handle

$data : string

Body data

Tags
since
1.6.1
Return values
int

Length of provided data

stream_headers()

Collect the headers as they are received

public stream_headers(resource|CurlHandle $handle, string $headers) : int
Parameters
$handle : resource|CurlHandle

cURL handle

$headers : string

Header string

Return values
int

Length of provided header

test()

Self-test whether the transport can be used.

public static test([array<string, bool> $capabilities = [] ]) : bool

The available capabilities to test for can be found in Capability.

Parameters
$capabilities : array<string, bool> = []

Optional. Associative array of capabilities to test against, i.e. ['<capability>' => true].

Return values
bool

Whether the transport can be used.


        
On this page

Search results