封装好的curl,get、post用法
来源:互联网 发布:java 小数点保留一位 编辑:程序博客网 时间:2024/05/07 08:52
function curl($url,$data=array(),$method,$setcooke=false,$cookie_file){
$ch = curl_init(); //1.初始化
curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式
//4.参数如下 禁止服务器端的验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//伪装请求来源,绕过防盗
//curl_setopt($ch,CURLOPT_REFERER,"http://wthrcdn.etouch.cn/");
//配置curl解压缩方式(默认的压缩方式)
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding:gzip'));
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0'); //指明以哪种方式进行访问
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
if($method=="POST"){//5.post方式的时候添加数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
if($setcooke==true){
//如果设置要请求的cookie,那么把cookie值保存在指定的文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
}else{
//就从文件中读取cookie的信息
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $tmpInfo;
}
$ch = curl_init(); //1.初始化
curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式
//4.参数如下 禁止服务器端的验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//伪装请求来源,绕过防盗
//curl_setopt($ch,CURLOPT_REFERER,"http://wthrcdn.etouch.cn/");
//配置curl解压缩方式(默认的压缩方式)
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding:gzip'));
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0'); //指明以哪种方式进行访问
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
if($method=="POST"){//5.post方式的时候添加数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
if($setcooke==true){
//如果设置要请求的cookie,那么把cookie值保存在指定的文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
}else{
//就从文件中读取cookie的信息
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $tmpInfo;
}
0 0
- 封装好的curl,get、post用法
- 封装好的curl,get、post用法
- curl post get封装
- 封装的curl 支持get post header
- php封装curl的post和get类
- PHP curl的用法(get and post)
- Linux curl 中get和post的用法详解
- 封装好的的 get 和 post网络请求
- UIday1602:封装好的GET 和 POST 方法
- 封装好的java调用Http------post/get方法
- CURL封装的php http和https请求网页模拟post get函数
- PHP curl实现get/post/delete/put封装
- PHP的CURL的POST/GET访问
- php的curl实现get和post
- php的curl实现get和post
- php的curl实现get和post
- CURL实现HTTP的GET POST方法
- CURL的get和post请求,简单明了
- Oracle 使用 with as 优化重复查询
- Java VisualVM分析JVM内存溢出
- 颠覆传统app格局的微信小程序来了:微信小程序开发环境搭建
- 3、RIOT操作系统的文件结构和CC2538在RIOT中的相关基础介绍
- linux exec 系列函数说明
- 封装好的curl,get、post用法
- Windows环境安装Trafodion客户端
- EAS 设置透视表,行样式,保存打印设置
- 如何区分寒咳嗽和热咳嗽
- MySQL 语句大全:创建、授权、查询、修改等
- 常见adb使用方法
- 数据库建表规范建议
- hadoop 报错Error: java.io.FileNotFoundException: Path is not a file:/xx1/xx2的解决办法
- [数据结构与算法]模式匹配与文本处理