curl post get封装
来源:互联网 发布:word修改属性软件 编辑:程序博客网 时间:2024/05/17 00:50
<?php/** * curl post get封装 * @author zhoug * @date 2012-09-11 */class curl { /** * * curl Post数据 * @param $url http地址 * @param $timeout 默认请求超时 * 成功返回字符串 */ static function curl_get_contents($url, $timeout = 5){ $userAgent ='xx5.com PHP5 (curl) ' . phpversion(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, true); curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 86400); // 缓存一天 $content = curl_exec($ch); curl_close($ch); return $content; } /** * * curl Post数据 * @param $url http地址 * @param $data &链接的字符串或者数组 * @param $timeout 默认请求超时 * 成功返回字符串 */ static function curl_post_contents($url, $data = array(), $timeout=10){ $userAgent ='xx5.com PHP5 (curl) ' . phpversion(); $referer = $url; if(!is_array($data) || !$url) return ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); //设置访问的url地址 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //设置超时 curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); //用户访问代理 User-Agent curl_setopt($ch, CURLOPT_REFERER, $referer); //设置 referer curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); //跟踪301 curl_setopt($ch, CURLOPT_POST, 1); //指定post数据 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //添加变量 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回结果 $content = curl_exec($ch); curl_close($ch); return $content; } static function makeQueryString($params) { if (is_string($params)) return $params; $query_string = array(); foreach ($params as $key => $value) { array_push($query_string, rawurlencode($key) . '=' . rawurlencode($value)); } $query_string = join('&', $query_string); return $query_string; }}
0 0
- curl post get封装
- 封装好的curl,get、post用法
- 封装好的curl,get、post用法
- 封装的curl 支持get post header
- php封装curl的post和get类
- PHP curl实现get/post/delete/put封装
- curl post and get
- CURL模拟POST/GET
- cURL-GET/POST/上传
- CURL GET POST
- php curl (get post)
- curl 常用命令 post、get
- php curl post get
- curl get post请求
- Curl发送get/post
- curl get&post
- curl get post语句
- Curl get/post传值
- 笔记
- 百度地图放饿了么我的地址定位(仿ele地图定位效果)
- 自定义Dialog:双日期选择器
- apache2三种模式及参数调优
- java可变参数
- curl post get封装
- python 通熟易懂的闭包
- sql server查看函数定义
- 程序员的自我修养-编译和链接
- TCP/IP、UDP、HTTP、Socket 各协议之间的联系与区别
- 关闭模式对话框 EndDialog
- HTML练习---制作聚美优品彩妆热卖产品列表页面
- oracle创建表空间及用户,导出导入数据备份
- Python 学习