Requests::request() WordPress Method
The Requests::request() method is used to make an HTTP request to a URL. This is useful for making requests to Wordpress sites. The method takes two arguments: the URL to request and an array of options. The options array can be used to set the HTTP method, headers, body, and other options.
Requests::request( string $url, array $headers = array(), array|null $data = array(), string $type = self::GET, array $options = array() ) #
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
- $url
(string)(Required)URL to request
- $headers
(array)(Optional)Extra headers to send with the request
Default value: array()
- $data
(array|null)(Optional)Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
Default value: array()
- $type
(string)(Optional)HTTP request type (use Requests constants)
Default value: self::GET
- $options
(array)(Optional)Options for the request (see description for more information)
Default value: array()
Return
Source
File: wp-includes/class-requests.php
public static function request($url, $headers = array(), $data = array(), $type = self::GET, $options = array()) { if (empty($options['type'])) { $options['type'] = $type; } $options = array_merge(self::get_default_options(), $options); self::set_defaults($url, $headers, $data, $type, $options); $options['hooks']->dispatch('requests.before_request', array(&$url, &$headers, &$data, &$type, &$options)); if (!empty($options['transport'])) { $transport = $options['transport']; if (is_string($options['transport'])) { $transport = new $transport(); } } else { $need_ssl = (stripos($url, 'https://') === 0); $capabilities = array('ssl' => $need_ssl); $transport = self::get_transport($capabilities); } $response = $transport->request($url, $headers, $data, $options); $options['hooks']->dispatch('requests.before_parse', array(&$response, $url, $headers, $data, $type, $options)); return self::parse_response($response, $url, $headers, $data, $options); }
Expand full source codeCollapse full source codeView on TracView on GitHub