A-A+

curl实现GET/POST

2015年08月27日 PHP 暂无评论 阅读 1,007 views 次

一个函数,利用curl实现GET/POST


function oauth_http($method,$header,$url,$data){
$method = $method ? $method : 'get';
if( $method == 'get') {
$ch = curl_init ();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_URL, $url );
$result = curl_exec ( $ch );
curl_close ( $ch );
return $result;
} elseif ( $method == 'post' ) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt ( $ch, CURLOPT_POST, TRUE );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$ret = curl_exec ( $ch );
curl_close ( $ch );
return $ret;
}
}

给我留言

Copyright © 严佳冬 保留所有权利.   Theme  Ality 百度地图 苏ICP备15015381号-1

用户登录

分享到: