标签:
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)把返回内容赋值给变量
$ch=curl_init(); curl_setopt($ch,CURLOPT_URL,"http://testopen.api.yaolan.com/api/user/reg"); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); $content=curl_exec($ch); var_dump($content); curl_close($ch);
curl post:
$data=array(‘uname‘=>‘zdctest‘,‘email‘=>‘zdc@yaolan.com‘,‘file_name‘ => ‘@/data/lnmp/autoreg/logs/log20150415.txt‘);//上传文件需要加@符号 $ch=curl_init(); curl_setopt($ch,CURLOPT_URL,"http://appuserreg.yaolan.com/reg.php"); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ch,CURLOPT_POST,true);//如果有下面的一行代码,这个可以不设置 curl_setopt($ch,CURLOPT_POSTFIELDS,$data); $content=curl_exec($ch); var_dump($content); curl_close($ch);
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‘); $url="http://testopen.api.yaolan.com/api/user/reg"; echo curl_post($url,$data);
标签:
原文地址:http://www.cnblogs.com/zhudongchang/p/4429675.html