本文主要是介绍curl_get和curl_post,伪造请求头,绕过防盗链下载文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//curl-getfunction curl_get($url, $timeout = 10){$ch = curl_init();//初始化curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //禁止服务器端的验证//伪装请求来源,绕过防盗curl_setopt($ch,CURLOPT_REFERER,"http://www.ding.com");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//服务器5秒内没有响应,脚本就会断开连接$file_contents = curl_exec($ch);//运行curlif (curl_errno($ch)) {return curl_error($ch);}curl_close($ch);return $file_contents;}//http://oss.houdunren.com/lesson_video/水印类/1,水印类简介.mp4$url = '要下载文件的地址';$filename = '要保存的下载文件名称';header("Content-Disposition:attachment;filename=".$filename);echo curl_get($url);
function curl_post($url, array $params = array(), $timeout = 5)
{$ch = curl_init();//初始化curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页curl_setopt($ch, CURLOPT_HEADER, 0);//设置headercurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);curl_setopt($ch, CURLOPT_POST, 1);//post提交方式curl_setopt($ch, CURLOPT_POSTFIELDS, $params);$data = curl_exec($ch);//运行curlcurl_close($ch);return ($data);
}
这篇关于curl_get和curl_post,伪造请求头,绕过防盗链下载文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!