标签:
POST请求
function curl_post($url=‘‘,$postdata=‘‘,$options=array()){ $ch=curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if(!empty($options)){ curl_setopt_array($ch, $options); } $data=curl_exec($ch); curl_close($ch); return $data; }
GET请求
function curl_get($url=‘‘,$options=array()){ $ch=curl_init($url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_TIMEOUT,5); if(!empty($options)){ curl_setopt_array($ch,$options); } $data=curl_exec($ch); curl_close($ch); return $data; }
CURL函数的GET和POST方式的两种写法(实现ajax跨域调用)
标签:
原文地址:http://www.cnblogs.com/kangshuai/p/5144291.html