WP_AI_Client_HTTP_Client::sendRequestWithOptions
Sends a PSR-7 request with transport options 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->sendRequestWithOptions( $request, $options ): ResponseInterface;
- $request(RequestInterface) (required)
- The PSR-7 request.
- $options(RequestOptions) (required)
- Transport options for the request.
Changelog
| Since 7.0.0 | Introduced. |
WP_AI_Client_HTTP_Client::sendRequestWithOptions() WP AI Client HTTP Client::sendRequestWithOptions code WP 7.0
public function sendRequestWithOptions( RequestInterface $request, RequestOptions $options ): ResponseInterface {
$args = $this->prepare_wp_args( $request, $options );
$url = (string) $request->getUri();
$response = wp_safe_remote_request( $url, $args );
if ( is_wp_error( $response ) ) {
$message = sprintf(
/* translators: 1: Request URL. 2: Error message. */
__( 'Network error occurred while sending request to %1$s: %2$s' ),
$url,
$response->get_error_message()
);
throw new NetworkException(
$message, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
$response->get_error_code() ? (int) $response->get_error_code() : 0
);
}
return $this->create_psr_response( $response );
}