Requests_Session::request() WordPress Method

The Requests_Session::request() method enables you to make HTTP requests to a specific URL. This is useful for making API calls or fetching data from a remote server. The method takes two parameters: the URL to request, and an optional array of data to be passed to the server.

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

Main interface for HTTP requests


Description

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

Top ↑

See also


Top ↑

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: Requests::GET

$options

(array)(Optional)Options for the request (see Requests::request)

Default value: array()


Top ↑

Return

(Requests_Response)


Top ↑

Source

File: wp-includes/Requests/Session.php

	public function request($url, $headers = array(), $data = array(), $type = Requests::GET, $options = array()) {
		$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));

		return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.