axios responseType流的PHP版本



我正在编写一个下载缩放会议记录(mp4文件)的函数。使用file_get_contents($url)和file_put_contents保存文件,抛出错误- 403 forbidden。

但是当我使用axios时,它会正确下载并保存文件。下面是工作代码-

axios({
method: "GET",
url: url,
responseType: "stream"
}).then(function (response) {
response.data.pipe(fs.createWriteStream("test.mp4"));
})

我尝试了copy(), file_get_contents(), fopen(),并尝试设置上下文和ini以下回答这个问题,但所有返回禁止,虽然相同的URL在axios中工作。

我可以使用Guzzle做到这一点。我不知道为什么(感激如果有人能解释),但这里是方式,如果有人正在寻找一个解决方案-

$client = new GuzzleHttpClient();
$request = new GuzzleHttpPsr7Request('GET', $url);
$res = $client->sendAsync($request)->wait();
file_put_contents('test.mp4', $res->getBody());

最新更新