Constants

HTTP_GET

HTTP_GET

GET HTTP Method

HTTP_POST

HTTP_POST

POST HTTP Method

HTTP_PUT

HTTP_PUT

PUT HTTP Method

HTTP_DELETE

HTTP_DELETE

DELETE HTTP Method

HTTP_HEAD

HTTP_HEAD

HEAD HTTP Method

Properties

$request_url

$request_url : 

The URL being requested.

Type

$request_headers

$request_headers : 

The headers being sent in the request.

Type

$request_body

$request_body : 

The body being sent in the request.

Type

$response

$response : 

The response returned by the request.

Type

$response_headers

$response_headers : 

The headers returned by the request.

Type

$response_body

$response_body : 

The body returned by the request.

Type

$response_code

$response_code : 

The HTTP status code returned by the request.

Type

$response_info

$response_info : 

Additional response data.

Type

$method

$method : 

The method by which the request is being made.

Type

$proxy

$proxy : 

Stores the proxy settings to use for the request.

Type

$username

$username : 

The username to use for the request.

Type

$password

$password : 

The password to use for the request.

Type

$curlopts

$curlopts : 

Custom CURLOPT settings.

Type

$debug_mode

$debug_mode : 

The state of debug mode.

Type

$request_class

$request_class : 

The default class to use for HTTP Requests (defaults to <RequestCore>).

Type

$response_class

$response_class : 

The default class to use for HTTP Responses (defaults to <ResponseCore>).

Type

$useragent

$useragent : 

Default useragent string to use.

Type

$read_file

$read_file : 

File to read from while streaming up.

Type

$read_stream

$read_stream : 

The resource to read from while streaming up.

Type

$read_stream_size

$read_stream_size : 

The size of the stream to read from.

Type

$read_stream_read

$read_stream_read : 

The length already read from the stream.

Type

$write_file

$write_file : 

File to write to while streaming down.

Type

$write_stream

$write_stream : 

The resource to write to while streaming down.

Type

$seek_position

$seek_position : 

Stores the intended starting seek position.

Type

$cacert_location

$cacert_location : 

The location of the cacert.pem file to use.

Type

$ssl_verification

$ssl_verification : 

The state of SSL certificate verification.

Type

$registered_streaming_read_callback

$registered_streaming_read_callback : 

The user-defined callback function to call when a stream is read from.

Type

$registered_streaming_write_callback

$registered_streaming_write_callback : 

The user-defined callback function to call when a stream is written to.

Type

$timeout

$timeout : integer

请求超时时间, 默认是5184000秒,6天

Type

integer

$connect_timeout

$connect_timeout : integer

连接超时时间,默认是10秒

Type

integer

Methods

__construct()

__construct(string  $url = null, string  $proxy = null, array  $helpers = null) : $this

Constructs a new instance of this class.

Parameters

string $url

(Optional) The URL to request or service endpoint to query.

string $proxy

(Optional) The faux-url to use for proxy settings. Takes the following format: proxy://user:pass@hostname:port

array $helpers

(Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class.

Returns

$this —

A reference to the current instance.

__destruct()

__destruct() : $this

Destructs the instance. Closes opened file handles.

Returns

$this —

A reference to the current instance.

set_credentials()

set_credentials(string  $user, string  $pass) : $this

Sets the credentials to use for authentication.

Parameters

string $user

(Required) The username to authenticate with.

string $pass

(Required) The password to authenticate with.

Returns

$this —

A reference to the current instance.

add_header()

add_header(string  $key, mixed  $value) : $this

Adds a custom HTTP header to the cURL request.

Parameters

string $key

(Required) The custom HTTP header to set.

mixed $value

(Required) The value to assign to the custom HTTP header.

Returns

$this —

A reference to the current instance.

remove_header()

remove_header(string  $key) : $this

Removes an HTTP header from the cURL request.

Parameters

string $key

(Required) The custom HTTP header to set.

Returns

$this —

A reference to the current instance.

set_method()

set_method(string  $method) : $this

Set the method type for the request.

Parameters

string $method

(Required) One of the following constants: , , , , .

Returns

$this —

A reference to the current instance.

set_useragent()

set_useragent(string  $ua) : $this

Sets a custom useragent string for the class.

Parameters

string $ua

(Required) The useragent string to use.

Returns

$this —

A reference to the current instance.

set_body()

set_body(string  $body) : $this

Set the body to send in the request.

Parameters

string $body

(Required) The textual content to send along in the body of the request.

Returns

$this —

A reference to the current instance.

set_request_url()

set_request_url(string  $url) : $this

Set the URL to make the request to.

Parameters

string $url

(Required) The URL to make the request to.

Returns

$this —

A reference to the current instance.

set_curlopts()

set_curlopts(array  $curlopts) : $this

Set additional CURLOPT settings. These will merge with the default settings, and override if there is a duplicate.

Parameters

array $curlopts

(Optional) A set of key-value pairs that set CURLOPT options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the CURLOPT_* constants, not strings.

Returns

$this —

A reference to the current instance.

set_read_stream_size()

set_read_stream_size(integer  $size) : $this

Sets the length in bytes to read from the stream while streaming up.

Parameters

integer $size

(Required) The length in bytes to read from the stream.

Returns

$this —

A reference to the current instance.

set_read_stream()

set_read_stream(resource  $resource, integer  $size = null) : $this

Sets the resource to read from while streaming up. Reads the stream from its current position until EOF or `$size` bytes have been read. If `$size` is not given it will be determined by <php:fstat()> and <php:ftell()>.

Parameters

resource $resource

(Required) The readable resource to read from.

integer $size

(Optional) The size of the stream to read.

Returns

$this —

A reference to the current instance.

set_read_file()

set_read_file(string  $location) : $this

Sets the file to read from while streaming up.

Parameters

string $location

(Required) The readable location to read from.

Returns

$this —

A reference to the current instance.

set_write_stream()

set_write_stream(resource  $resource) : $this

Sets the resource to write to while streaming down.

Parameters

resource $resource

(Required) The writeable resource to write to.

Returns

$this —

A reference to the current instance.

set_write_file()

set_write_file(string  $location) : $this

Sets the file to write to while streaming down.

Parameters

string $location

(Required) The writeable location to write to.

Returns

$this —

A reference to the current instance.

set_proxy()

set_proxy(string  $proxy) : $this

Set the proxy to use for making requests.

Parameters

string $proxy

(Required) The faux-url to use for proxy settings. Takes the following format: proxy://user:pass@hostname:port

Returns

$this —

A reference to the current instance.

set_seek_position()

set_seek_position(integer  $position) : $this

Set the intended starting seek position.

Parameters

integer $position

(Required) The byte-position of the stream to begin reading from.

Returns

$this —

A reference to the current instance.

register_streaming_read_callback()

register_streaming_read_callback(string|array|\OSS\Http\function  $callback) : $this

Register a callback function to execute whenever a data stream is read from using <CFRequest::streaming_read_callback()>.

The user-defined callback function should accept three arguments:

  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • $file_handle - resource - Required - The file handle resource that represents the file on the local file system.
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.

Parameters

string|array|\OSS\Http\function $callback

(Required) The callback function is called by <php:call_user_func()>, so you can pass the following values:

  • The name of a global function to execute, passed as a string.
  • A method to execute, passed as array('ClassName', 'MethodName').
  • An anonymous function (PHP 5.3+).

Returns

$this —

A reference to the current instance.

register_streaming_write_callback()

register_streaming_write_callback(string|array|\OSS\Http\function  $callback) : $this

Register a callback function to execute whenever a data stream is written to using <CFRequest::streaming_write_callback()>.

The user-defined callback function should accept two arguments:

  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.

Parameters

string|array|\OSS\Http\function $callback

(Required) The callback function is called by <php:call_user_func()>, so you can pass the following values:

  • The name of a global function to execute, passed as a string.
  • A method to execute, passed as array('ClassName', 'MethodName').
  • An anonymous function (PHP 5.3+).

Returns

$this —

A reference to the current instance.

streaming_read_callback()

streaming_read_callback(resource  $curl_handle, resource  $file_handle, integer  $length) : \OSS\Http\binary

A callback function that is invoked by cURL for streaming up.

Parameters

resource $curl_handle

(Required) The cURL handle for the request.

resource $file_handle

(Required) The open file handle resource.

integer $length

(Required) The maximum number of bytes to read.

Returns

\OSS\Http\binary —

Binary data from a stream.

streaming_write_callback()

streaming_write_callback(resource  $curl_handle, \OSS\Http\binary  $data) : integer

A callback function that is invoked by cURL for streaming down.

Parameters

resource $curl_handle

(Required) The cURL handle for the request.

\OSS\Http\binary $data

(Required) The data to write.

Returns

integer —

The number of bytes written.

prep_request()

prep_request() : resource

Prepares and adds the details of the cURL request. This can be passed along to a <php:curl_multi_exec()> function.

Returns

resource —

The handle for the cURL object.

process_response()

process_response(resource  $curl_handle = null, string  $response = null) : \OSS\Http\ResponseCore

Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the data stored in the `curl_handle` and `response` properties unless replacement data is passed in via parameters.

Parameters

resource $curl_handle

(Optional) The reference to the already executed cURL request.

string $response

(Optional) The actual response content itself that needs to be parsed.

Returns

\OSS\Http\ResponseCore

A object containing a parsed HTTP response.

send_request()

send_request(boolean  $parse = false) : string

Sends the request, calling necessary utility functions to update built-in properties.

Parameters

boolean $parse

(Optional) Whether to parse the response with ResponseCore or not.

Returns

string —

The resulting unparsed data from the request.

get_response_header()

get_response_header(string  $header = null) : string|array

Get the HTTP response headers from the request.

Parameters

string $header

(Optional) A specific header value to return. Defaults to all headers.

Returns

string|array —

All or selected header values.

get_response_body()

get_response_body() : string

Get the HTTP response body from the request.

Returns

string —

The response body.

get_response_code()

get_response_code() : string

Get the HTTP response code from the request.

Returns

string —

The HTTP response code.