PHP调用API接口

/*这是一个接口调用的方法(post)*/
$url = 'http://localhost/testmysql.php';
$sl_data=array(
'uid'=>1,
'user_by'=>'get_userinfo'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);//要访问的地址
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//执行结果是否被返回,0是返回,1是不返回
curl_setopt($ch, CURLOPT_POST, 1);// 发送一个常规的POST请求
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($sl_data));
$output = curl_exec($ch);//执行并获取数据
echo $output;
curl_close($ch);

猜你喜欢

转载自www.cnblogs.com/ranqingfeng/p/9122424.html