WP_Http::_dispatch_request( string $url, array $args ): array|WP_Error

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

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

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.

See also

Parameters

$urlstringrequired
URL to request.
$argsarrayrequired
Request arguments.

Return

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

Source

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 );
}

Hooks

do_action( ‘http_api_debug’, array|WP_Error $response, string $context, string $class, array $parsed_args, string $url )

Fires after an HTTP API response is received and before the response is returned.

apply_filters( ‘http_response’, array $response, array $parsed_args, string $url )

Filters a successful HTTP API response immediately before the response is returned.

Changelog

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

User Contributed Notes

You must log in before being able to contribute a note or feedback.