WP_AI_Client_HTTP_Client::sendRequestpublicWP 7.0.0

Sends a PSR-7 request and returns a PSR-7 response.

Method of the class: WP_AI_Client_HTTP_Client{}

No Hooks.

Returns

ResponseInterface. The PSR-7 response.

Usage

$WP_AI_Client_HTTP_Client = new WP_AI_Client_HTTP_Client();
$WP_AI_Client_HTTP_Client->sendRequest( $request ): ResponseInterface;
$request(RequestInterface) (required)
The PSR-7 request.

Changelog

Since 7.0.0 Introduced.

WP_AI_Client_HTTP_Client::sendRequest() code WP 7.0

public function sendRequest( RequestInterface $request ): ResponseInterface {
	$args = $this->prepare_wp_args( $request );
	$url  = (string) $request->getUri();

	$response = wp_safe_remote_request( $url, $args );

	if ( is_wp_error( $response ) ) {
		$message = sprintf(
			/* translators: 1: HTTP method (e.g. GET, POST). 2: Request URL. 3: Error message. */
			__( 'Network error occurred while sending %1$s request to %2$s: %3$s' ),
			$request->getMethod(),
			$url,
			$response->get_error_message()
		);
		throw new NetworkException( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
	}

	return $this->create_psr_response( $response );
}