Sends a PSR-7 request and returns a PSR-7 response.
Parameters
$requestWordPressAiClientDependenciesPsrHttpMessageRequestInterfacerequired- The PSR-7 request.
Source
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 );
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.