企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 安装 ``` composer require psr/http-client ``` ## 接口 <details> <summary>Psr\Http\Client\ClientInterface</summary> ``` namespace Psr\Http\Client; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; interface ClientInterface { /** * 发送一个 PSR-7 标准的请求,返回一个 PSR-7 格式的响应. * * @param RequestInterface $request * * @return ResponseInterface * * @throws \Psr\Http\Client\ClientExceptionInterface 发生错误将抛出客户端异常接口对象 * */ public function sendRequest(RequestInterface $request): ResponseInterface; } ``` </details> <br /> <details> <summary>Psr\Http\Client\ClientExceptionInterface</summary> ``` namespace Psr\Http\Client; /** * 每个HTTP客户端相关的异常都必须实现此接口. */ interface ClientExceptionInterface extends \Throwable { } ``` </details> <br /> <details> <summary>Psr\Http\Client\RequestExceptionInterface</summary> ``` namespace Psr\Http\Client; use Psr\Http\Message\RequestInterface; /** * 请求失败时的异常. * * 举例: * - 请求无效 (e.g. 参数缺失) * - 请求运行错误 (e.g. 响应体不可见) */ interface RequestExceptionInterface extends ClientExceptionInterface { /** * 获取请求对象. * * 请求对象可能和客户端接口发送的对象不一致. * * @return RequestInterface */ public function getRequest(): RequestInterface; } ``` </details> <br /> <details> <summary>Psr\Http\Client\NetworkExceptionInterface</summary> ``` namespace Psr\Http\Client; use Psr\Http\Message\RequestInterface; /** * 因网络原因导致请求无法完成时抛出该异常. * * 抛出该异常将没有响应体,因为收不到响应体时也会抛出这个异常. * * 举例:域名不能解析或连接失败. */ interface NetworkExceptionInterface extends ClientExceptionInterface { /** * 返回请求对象. * * 返回的请求对象可能和客户端接口发送的对象不一致. * * @return RequestInterface */ public function getRequest(): RequestInterface; } ``` </details> <br />