Requests::request() public WP 1.0
Main interface for HTTP requests
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 {@see getTransport()} (string|Requests_Transport, default: {@see 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)
{} Это метод класса: Requests{}
Хуков нет.
Возвращает
Requests_Response
. Null. Ничего.
Использование
$result = Requests::request( $url, $headers, $data, $type, $options );
- $url(строка) (обязательный)
- URL to request
- $headers(массив)
- Extra headers to send with the request
- $data(массив/null)
- 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 description for more information)
Код Requests::request() Requests::request WP 5.7
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 = (0 === stripos($url, 'https://'));
$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);
}