curl请求
来源:互联网 发布:数据质量监控系统 编辑:程序博客网 时间:2024/06/14 10:44
function doPosts($url, $req = array(), $isPost = 1,$header = array()){ // create a new cURL resource //Header("Content-Type","text/html;charset=utf-8"); $ch = curl_init(); $reqs = ''; foreach($req AS $k => $v){ if($reqs) $reqs .= "&$k=$v"; else $reqs = "$k=$v"; }// $header = array("Content-Type","text/html;charset=gb2312"); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, $isPost);//post方式提交 curl_setopt($ch, CURLOPT_POSTFIELDS, $reqs);//要提交的内容 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//https请求 //curl_setopt($ch, CURLOPT_SSLVERSION, 6); //SSL版本设定,暂时不需要 curl_setopt($ch, CURLOPT_TIMEOUT, 30);// print_r($reqs); // grab URL and pass it to the browser //print_r($reqs); if(!$res = curl_exec($ch)) { echo "Curl error : " . curl_error($ch); curl_close($ch); return false; } curl_close($ch); return $res; }
public static function curl($url, $postFields = null, $header = array()) { $ch = curl_init ($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); $response = curl_exec($ch); //$response = json_decode(json_encode(simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA)), true); if(curl_errno($ch)){ print curl_error($ch); } curl_close($ch); return $response;}
阅读全文
0 0
- curl请求
- curl请求
- curl请求
- CURL 远程请求调用
- curl https请求 解决方案
- curl请求页面
- php curl请求转发
- PHP - CURL 模拟请求
- CURL 请求错误代码
- PHP CURL 发送请求
- curl https get请求
- curl请求方法
- cURL模拟POST请求
- curl命令发送请求
- CURL发送HTTP请求
- CURL模拟post请求
- php curl请求
- curl模拟浏览器请求
- Android 杂知识总结
- 画出网络结构
- 提高编码技能的10个窍门
- 如何高效利用GitHub
- VS2008工程中 附加依赖项 和 附加库目录
- curl请求
- 快速搭建 ShadowSocks 的脚本
- hdoj 1027 Ignatius and the Princess II
- 分布式存储系统可靠性如何估算?
- (121)编辑时间轴
- java集合
- Java内存模型-防止内存泄漏
- SpringMVC 自定义类型转换器
- vue新建项目(二)安装element-ui