php curl super long url malformed

丶灬走出姿态 提交于 2019-12-13 04:25:58

问题


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!

The below is what I have in my php script:

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

Error message:

curl: (3) <url> malformed

Sample url to test download:

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

回答1:


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); 



回答2:


This error can be resolved through using urlencode

 $url = urlencode ( $url )

This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables.

Hope this solve answer



来源:https://stackoverflow.com/questions/15589345/php-curl-super-long-url-malformed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!