Overview

Packages

  • Requests
    • Authentication
    • Cookies
    • Proxy
    • Session
    • Transport
    • Utilities

Classes

  • Requests_Session
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated

Warning! You are currently reading the documentation for Requests 1.x.

It is recommended to upgrade to Requests 2.x at your earliest convenience. Upgrading to Requests 2.x is fairly straight-forward.
A full list of the changes can be found in the Changelog.

Visit the documentation for Requests_Session in Requests 2.x.

Class Requests_Session

Session handler for persistent requests and default parameters

Allows various options to be set as default values, and merges both the options and URL properties together. A base URL can be set for all requests, with all subrequests resolved from this. Base options can be set (including a shared cookie jar), then overridden for individual requests.

Package: Requests\Session
Located at Requests/Session.php
Methods summary
public
# __construct( string|null $url = null, array $headers = array(), array $data = array(), array $options = array() )

Create a new session

Create a new session

Parameters

$url
Base URL for requests
$headers
Default headers for requests
$data
Default data for requests
$options
Default options for requests
public mixed|null
# __get( string $key )

Get a property's value

Get a property's value

Parameters

$key
Property key

Returns

mixed|null
Property value, null if none found
public
# __set( string $key, mixed $value )

Set a property's value

Set a property's value

Parameters

$key
Property key
$value
Property value
public
# __isset( string $key )

Remove a property's value

Remove a property's value

Parameters

$key
Property key
public
# __unset( string $key )

Remove a property's value

Remove a property's value

Parameters

$key
Property key
public Requests_Response
# get( string $url, array $headers = array(), array $options = array() )

Send a GET request

Send a GET request

Parameters

$url
$headers
$options

Returns

Requests_Response

See

Requests_Session::request()
public Requests_Response
# head( string $url, array $headers = array(), array $options = array() )

Send a HEAD request

Send a HEAD request

Parameters

$url
$headers
$options

Returns

Requests_Response

See

Requests_Session::request()
public Requests_Response
# delete( string $url, array $headers = array(), array $options = array() )

Send a DELETE request

Send a DELETE request

Parameters

$url
$headers
$options

Returns

Requests_Response

See

Requests_Session::request()
public Requests_Response
# post( string $url, array $headers = array(), array $data = array(), array $options = array() )

Send a POST request

Send a POST request

Parameters

$url
$headers
$data
$options

Returns

Requests_Response

See

Requests_Session::request()
public Requests_Response
# put( string $url, array $headers = array(), array $data = array(), array $options = array() )

Send a PUT request

Send a PUT request

Parameters

$url
$headers
$data
$options

Returns

Requests_Response

See

Requests_Session::request()
public Requests_Response
# patch( string $url, array $headers, array $data = array(), array $options = array() )

Send a PATCH request

Send a PATCH request

Note: Unlike Requests_Session::post() and Requests_Session::put(), $headers is required, as the specification recommends that should send an ETag

Parameters

$url
$headers
$data
$options

Returns

Requests_Response

See

Requests_Session::request()

Link

https://tools.ietf.org/html/rfc5789
public Requests_Response
# request( string $url, array $headers = array(), array|null $data = array(), string $type = Requests::GET, array $options = array() )

Main interface for HTTP requests

Main interface for HTTP requests

This method initiates a request and sends it via a transport before parsing.

Parameters

$url
URL to request
$headers
Extra headers to send with the request
$data
Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
$type
HTTP request type (use Requests constants)
$options
Options for the request (see Requests::request)

Returns

Requests_Response

Throws

Requests_Exception
On invalid URLs (nonhttp)

See

Requests::request()
public array
# request_multiple( array $requests, array $options = array() )

Send multiple HTTP requests simultaneously

Send multiple HTTP requests simultaneously

Parameters

$requests
Requests data (see Requests::request_multiple)
$options
Global and default options (see Requests::request)

Returns

array
Responses (either Requests_Response or a Requests_Exception object)

See

Requests::request_multiple()
protected array
# merge_request( array $request, boolean $merge_options = true )

Merge a request's data with the default data

Merge a request's data with the default data

Parameters

$request
Request data (same form as Requests_Session::request_multiple())
$merge_options
Should we merge options as well?

Returns

array
Request data
Properties summary
public string|null $url

Base URL for requests

Base URL for requests

URLs will be made absolute using this as the base

# null
public array $headers

Base headers for requests

Base headers for requests

# array()
public array $data

Base data for requests

Base data for requests

If both the base data and the per-request data are arrays, the data will be merged before sending the request.

# array()
public array $options

Base options for requests

Base options for requests

The base options are merged with the per-request data for each request. The only default option is a shared cookie jar between requests.

Values here can also be set directly via properties on the Session object, e.g. $session->useragent = 'X';

# array()
Requests 1.8.1 API Documentation API documentation generated by ApiGen