symfony - 如何解决“没有扩展能够加载'monolog.http_client'的配置”
问题描述
我想使用 symfony 的 HttpClientInterface,所以我将它添加到 __construct 中,如下所示:
private HttpClientInterface $client;
/**
* @param HttpClientInterface $client
*/
public function __construct(
HttpClientInterface $client
) {
$this->client = $client;
}
在我的函数中只是一个简单的请求:
$response = $this->client->request(
'GET',
'https://mywebsite.com/api/call/myId'
);
所以当我尝试运行它时,我得到了这个错误:
Cannot autowire service "App\MyService": argument "$client" of method "__construct()" references interface "Symfony\Contracts\HttpClient\HttpClientInterface" but no such service exists. You should maybe alias this interface to the existing "monolog.http_client" service.
如上所述,我尝试将其添加到服务中,但也出现错误:
像这样(monolog.http_client: 或 http_client:)
错误:这里没有扩展能够加载“monolog.http_client”的配置
所以我真的不知道如何解决这个问题!
解决方案
我不得不在框架下添加 http_client: 在 services.yml
推荐阅读
- python - Python Google 图片下载库错误
- python - 电话号码字段包含美国电话号码,需要修改为国际格式,电话号码前加“+1-”
- angular - highcharts 中的图表选项未从 ngoninit 中的函数调用更新
- unit-testing - NUnit 延迟约束似乎在 Unity3d 中不起作用
- swift - 下一个对象实例 IGListKit
- python - 数据集中的空值
- python - 如何在没有 /F 的 Windows 上使用 taskkill 杀死 python
- shell - 在 Makefile 中拆分和剪切字符串
- yaml - 无法将示例添加到 YAML 文件
- android - Android位图压缩webp到jpg不改变mime类型