php curl超长url格式不正确 [英] php curl super long url malformed

查看:1601
本文介绍了php curl超长url格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个长的网址嵌套在一个变量:$ mp4,并试图下载它与curl,但我得到格式错误。

I have a long url nested in a variable: $mp4, and trying to download it with curl but i'm getting malformed error. Please help me if you can, thank you in advance!

以下是我在我的php脚本中:

The below is what I have in my php script:

exec("curl -o $fnctid.mp4 \"$mp4\"");

错误讯息:

curl: (3) <url> malformed

测试下载的示例网址:

http://f26.stream.nixcdn.com/6f4df1d8c248cf149b846c24d32f1c35/514e0209/PreNCT5/22-TaylorSwift-2426783.mp4


推荐答案

当前网址正在返回 408 - Request Timeout 你就是这个简单的代码:

The current url is returning 408 - Request Timeout if that is fixed you are you this simple code :

$url = 'http://f26.stream.nixcdn.com/6f4df1d8c248cf149b846c24d32f1c35/514e0209/PreNCT5/22-TaylorSwift-2426783.mp4';
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';


$file = __DIR__ . DIRECTORY_SEPARATOR . basename($url);
$fp = fopen($file, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 320);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
echo curl_exec($ch);

var_dump(curl_getinfo($ch));   // return request information 


curl_close($ch);
fclose($fp); 

这篇关于php curl超长url格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆