我想使用 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”的配置
所以我真的不知道如何解决这个问题!