curl get:

1)直接输出

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,"http://testopen.api.yaolan.com/api/user/reg");
curl_exec($ch);
curl_close($ch);

2)curl_get函数

function curl_get($url){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$content=curl_exec($ch);
curl_close($ch);
return $content;
}

curl_post 函数:

function curl_post($url,$data=array()){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,true);//如果有下面的一行代码,这个可以不设置
curl_setopt($ch,CURLOPT_POSTFIELDS,$data); $content=curl_exec($ch);
curl_close($ch);
return $content;
}
$data=array('uname'=>'zdctest','email'=>'zdc@yaolan.com');
//$data=array('uname'=>'zdctest','email'=>'zdc@yaolan.com','file_name' => '@/data/lnmp/autoreg/logs/log20150415.txt');//上传文件需要加@符号  php 5.6 之后要加 curl_setopt($ch, CURLOPT_SAFE_UPLOAD,false);才能上传成功
$url="http://testopen.api.yaolan.com/api/user/reg"; echo curl_post($url,$data);

携带header post

    public static function  curlPost($url,$data=array(),$header=array()){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,true);//如果有下面的一行代码,这个可以不设置
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
empty($header) or curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $content=curl_exec($ch);
curl_close($ch);
return $content;
}

-----------------------------------------新版

curl:request

    public static function curlRequest($url,$method='post',$data=array(),$header=array()){
$ch = curl_init(); //初始化CURL句柄
curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //设置请求方式
empty($data) or curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串
empty($header) or curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//设置提交header
0===strpos($url,'https:') and curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https请求加这个代码
$content=curl_exec($ch);
curl_close($ch);
return $content;
}

curl post  get

//post 函数
function curl_post($url,$data=array(),array $header=array()){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST,true);//如果有下面的一行代码,这个可以不设置
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
0===strpos($url,'https:') and curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https请求加这个代码
empty($header) or curl_setopt($ch, CURLOPT_HTTPHEADER, $header); $content=curl_exec($ch);
curl_close($ch);
return $content;
} //get函数携带 header
function curl_get($url,array $header=array()){
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
0===strpos($url,'https:') and curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https请求加这个代码
empty($header) or curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$content=curl_exec($ch);
curl_close($ch);
return $content;
}

curlRequest:(new)

 private function curlRequest($url,$method='post',$data=array(),$header=array()){
$ch = curl_init(); //初始化CURL句柄
curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出
if('post'!=strtolower($method)){
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //设置请求方式
}else{
curl_setopt($ch,CURLOPT_POST,true);
} is_array($data) and $data=http_build_query($data);
empty($data) or curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串 empty($header) or curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//设置提交header
0===strpos($url,'https:') and curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https请求加这个代码
$content=curl_exec($ch);
curl_close($ch);
return $content;
}

  

curl ,post,get (原创)的更多相关文章

  1. (原创) cocos2dx使用Curl连接网络(客户端)

    0. 环境: winxpsp3, vs2010, cocos2dx@2.1.4 1. 新建一个Helloworld工程 2. HelloworldScene.h里面重写virtual bool ccT ...

  2. 【原创】Linux基础之curl

    http请求过程如下: # curl -v http://www.baidu.com % Total % Received % Xferd Average Speed Time Time Time C ...

  3. 原创docker dcos 的安装

    原创哈,上个星期无意间发现了一个可以好东西 DC/OS https://dcos.io 这个是官网哈 然后就痛苦的折磨了一个多星期; 基本是参照到https://dcos.io/docs/1.7/ad ...

  4. curl常用选项详解

    curl常用选项详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 又是下班的时间了,让我们一起来学习一下今天的Linux命令吧~我一半只把自己常用的参数列出来,其他的有但是我们几 ...

  5. 基于PHP的cURL快速入门

    cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性,以及在PHP中如 ...

  6. Linux中Curl命令couldn't connect to host解决方案 php操作Curl(http,https)无法获取远程数据解决方案

    本人在做百度账户第三方登录接口,获取百度token,利用php操作curl post方式发送请求token,出现couldn't connect to host错误.经过调试测试,最后终于成功.回头写 ...

  7. php通过curl实现bigpipe

    BigPipe是facebook发明的一种页面加载技术.其实也不是什么新技术了,也有很多文章进行说明.但是在网上,具体讲如何使用php实现bigpipe的文章很少,并且有些文章还不很准确.bigpip ...

  8. 误mlogc.c:32:23: error: curl/curl.h: No such file or directory

    出现以下错误: mlogc.c:32:23: error: curl/curl.h: No such file or directory mlogc.c:1091: error: expected ' ...

  9. zabbix 实现curl 显示器

    1.进入Configure->Templates 2. 新建一个模板 3.新建模板,并保存 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFpND ...

随机推荐

  1. 2C课程笔记分享_StudyJams_2017

    课程2C-实践:创建交互式应用 概述 课程2C的内容主要是练习巩固2A.2B中讲解的内容,并设计实现一款篮球比赛的计分板应用及其界面的美化. Warm-Up:准备活动 新建项目PracticeSet2 ...

  2. iis 7.5 ftp site用户名不能是 'ftp'?

    在windows server 2008 r2上配置一个iis ftp site,创建了一个名为 ftp 的账号,并添加到允许规则中,可总是出现: Connected to ***.***.***.* ...

  3. An interesting scroll background------ActionScript3.0

    package { /* *@ ClassName : package::backGround *@ INTRO : the continuously scroll background *@ Aut ...

  4. mysql 统计按天、星期、按月数据的各种 sql 语句 (转录)

    文章主要是作为知识整理,内容略有修改,方便以后查阅,内容转摘至 陈宇衡的个人博客,欢迎前去围观. 作为演示效果,先创建一个测试表,在插入两条数据(注:时间为 datetime 类型,unix 时间戳需 ...

  5. RSA PKCS1 填充方式

    1)RSA_PKCS1_PADDING 填充模式,最常用的模式 要求:输入 必须 比 RSA 钥模长(modulus) 短至少11个字节, 也就是 RSA_size(rsa) – 11    如果输入 ...

  6. html 图片翻转

    var Lb = false; var Ub = false; function rotate(obj) { if (obj == "L") { if (Lb == false) ...

  7. wget 批量下载网站目录下的文件

    执行如下命令就会自动下载 http://www.iyunwei.com/docs/ 下面的所有文件: wget -nd -r -l1 --no-parent http://www.iyunwei.co ...

  8. Python字符串格式化--formate()的应用

    1.简单运用字符串类型格式化采用format()方法,基本使用格式是:转自 <模板字符串>.format(<逗号分隔的参数>) 调用format()方法后会返回一个新的字符串, ...

  9. BZOJ 3319: 黑白树 树+并查集+未调完+神题

    Code: #include<bits/stdc++.h> #define maxn 1000003 using namespace std; char *p1,*p2,buf[10000 ...

  10. vue小白学习笔记

    <div id="div"> <h2>{{ key }}</h2> </div> new Vue ({ el : "#di ...