headermask image

header image

一个使用curl发送http post请求的函数

function http_post($url,$post){

$c=curl_init();//初始化curl session

//设置目标URL
curl_setopt($c,CURLOPT_URL,$url);

//使用post请求,并且加入数据
curl_setopt($c,CURLOPT_POST,true);
curl_setopt($c,CURLOPT_POSTFIELDS,$post);

//设置curl返回方式
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);

//执行post请求并返回
return curl_exec($c);

}
$fields=array('uid'=>'120','name'=>'frank');
echo http_post('http://www.hechuang.org/curl',http_build_query($fields));
?>



If you liked my post, feel free to subscribe to my rss feeds

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*