[英]Symfony equivalent of curl_setopt using the httpClientInterface service
我需要调用外部 API。 API 文档说
curl_setopt($ch, CURLOPT_URL, "https://api.simkl.com/search/file");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{
\"file\": \"Were.The.Fugawis.S01E01E02.WS.DSR.x264-NY2.mkv\",
\"part\": 1
}");
我正在使用 Symfony 并尝试正确使用给定的服务HttpClientInterface
进行调用:
// $this->client containing the Symfony\Contracts\HttpClient\HttpClientInterface service
$response = $this->client->request('POST', 'https://api.simkl.com/search/file', [
'file' => 'Death_Note-01',
]);
当然它返回错误
不支持的选项“文件”传递给 Symfony\\Component\\HttpClient\\NativeHttpClient”,你的意思是 cafile”?
如何使用 Symfony 提供的 HttpClientInterface 正确设置调用选项?
在 Symfony 文档中的任何地方都找不到答案。
您可以在此处找到文档:
$response = $this->client->request('POST', 'https://api.simkl.com/search/file', [
'file' => 'Death_Note-01',
'extra' => [
'curl' => [
CURLOPT_POSTFIELDS => "{
\"file\": \"Were.The.Fugawis.S01E01E02.WS.DSR.x264-NY2.mkv\",
\"part\": 1
}",
],
],
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.