Warning: This method has been deprecated. Use WP_Http::request() instead.

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use WP_Http::request() instead.

WP_Http::_dispatch_request() WordPress Method

The WP_Http::_dispatch_request() method is used to send a HTTP request to a remote server and receive a response. This method is used by the WP_Http::request() method when making HTTP requests.

WP_Http::_dispatch_request( string $url, array $args ) #

Dispatches a HTTP request to a supporting transport.


Description

Tests each transport in order to find a transport which matches the request arguments. Also caches the transport instance to be used later.

The order for requests is cURL, and then PHP Streams.

Top ↑

See also


Top ↑

Parameters

$url

(string)(Required)URL to request.

$args

(array)(Required)Request arguments.


Top ↑

Return

(array|WP_Error) Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error.


Top ↑

Source

File: wp-includes/class-wp-http.php

	private function _dispatch_request( $url, $args ) {
		static $transports = array();

		$class = $this->_get_first_available_transport( $args, $url );
		if ( ! $class ) {
			return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) );
		}

		// Transport claims to support request, instantiate it and give it a whirl.
		if ( empty( $transports[ $class ] ) ) {
			$transports[ $class ] = new $class;
		}

		$response = $transports[ $class ]->request( $url, $args );

		/** This action is documented in wp-includes/class-wp-http.php */
		do_action( 'http_api_debug', $response, 'response', $class, $args, $url );

		if ( is_wp_error( $response ) ) {
			return $response;
		}

		/** This filter is documented in wp-includes/class-wp-http.php */
		return apply_filters( 'http_response', $response, $args, $url );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.1.0Use WP_Http::request()
3.2.0Introduced.

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.