Requests::request( string $url, array $headers = array(), array|null $data = array(), string $type = self::GET, array $options = array() ): Requests_Response

In this article

Main interface for HTTP requests

Description

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

The $options parameter takes an associative array with the following options:

  • timeout: How long should we wait for a response? Note: for cURL, a minimum of 1 second applies, as DNS resolution operates at second-resolution only.
    (float, seconds with a millisecond precision, default: 10, example: 0.01)
  • connect_timeout: How long should we wait while trying to connect? (float, seconds with a millisecond precision, default: 10, example: 0.01)
  • useragent: Useragent to send to the server (string, default: php-requests/$version)
  • follow_redirects: Should we follow 3xx redirects? (boolean, default: true)
  • redirects: How many times should we redirect before erroring? (integer, default: 10)
  • blocking: Should we block processing on this request? (boolean, default: true)
  • filename: File to stream the body to instead.
    (string|boolean, default: false)
  • auth: Authentication handler or array of user/password details to use for Basic authentication (Requests_Auth|array|boolean, default: false)
  • proxy: Proxy details to use for proxy by-passing and authentication (Requests_Proxy|array|string|boolean, default: false)
  • max_bytes: Limit for the response body size.
    (integer|boolean, default: false)
  • idn: Enable IDN parsing (boolean, default: true)
  • transport: Custom transport. Either a class name, or a transport object. Defaults to the first working transport from getTransport() (string|Requests_Transport, default: getTransport())
  • hooks: Hooks handler.
    (Requests_Hooker, default: new Requests_Hooks())
  • verify: Should we verify SSL certificates? Allows passing in a custom certificate file as a string. (Using true uses the system-wide root certificate store instead, but this may have different behaviour across transports.) (string|boolean, default: library/Requests/Transport/cacert.pem)
  • verifyname: Should we verify the common name in the SSL certificate? (boolean, default: true)
  • data_format: How should we send the $data parameter? (string, one of ‘query’ or ‘body’, default: ‘query’ for HEAD/GET/DELETE, ‘body’ for POST/PUT/OPTIONS/PATCH)

Parameters

$urlstringrequired
URL to request
$headersarrayoptional
Extra headers to send with the request

Default:array()

$dataarray|nulloptional
Data to send either as a query string for GET/HEAD requests, or in the body for POST requests

Default:array()

$typestringoptional
HTTP request type (use Requests constants)

Default:self::GET

$optionsarrayoptional
Options for the request (see description for more information)

Default:array()

Return

Requests_Response

Source

User Contributed Notes

You must log in before being able to contribute a note or feedback.