Axios ResponseType流的PHP版本

发布于 2025-02-13 02:57:35 字数 591 浏览 0 评论 0原文

我正在编写下载Zoom Meeting Recording(MP4文件)的功能。使用file_get_contents($ url)和file_put_contents来保存文件,它抛出了错误-403禁止。

但是,当我使用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中起作用。

I am writing a function which download Zoom Meeting Recording (mp4 file). Using file_get_contents($url) and file_put_contents to save the file, it was throwing error - 403 forbidden.

But when I do it using axios, it download and saves the file properly. Here is the working code -

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

I tried copy(), file_get_contents(), fopen() and also tried setting context and ini following answers to this question but all returning forbidden though the same URL works in axios.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别再吹冷风 2025-02-20 02:57:35

我能够使用guzzle做到这一点。我不确定为什么(感谢某人可以解释),但是如果有人正在寻找解决方案 -

$client = new GuzzleHttp\Client();
$request = new GuzzleHttp\Psr7\Request('GET', $url);
$res = $client->sendAsync($request)->wait();
file_put_contents('test.mp4', $res->getBody());

I was able to do it using Guzzle. I'm not sure why (appreciated if someone can explain) but here is the way if someone is looking for a solution -

$client = new GuzzleHttp\Client();
$request = new GuzzleHttp\Psr7\Request('GET', $url);
$res = $client->sendAsync($request)->wait();
file_put_contents('test.mp4', $res->getBody());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文