Requests::request()

最后更新于:2021-11-26 00:06:20

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

Main interface for HTTP requests

参数

$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()

响应

(Requests_Response)

源文件

文件: gc-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);
	}