php获取api接口数据的方法
心屿·Balloon studi
2024-06-05 19:40:52
最佳回答
1get方式请求api接口file_get_contents函数1该信息未经授权抓取自百度经验2$a = file_get_contents("http://www.a.com");如果接口返回json格式的数据,则要转为数组$re = json_decode($a,true);**ost方式请求接口curl扩展函数4function request_by_curl($remote_server,$post_string,$use_post=true){ if(function_ex**ts('curl_init')){ $ch = curl_init(); curl_setopt($ch,curlopt_url,$remote_server); if($use_post){ curl_setopt($ch,curlopt_post, 1); curl_setopt($ch,curlopt_postfields,$post_string); } curl_setopt($ch,curlopt_returntransfer,true); $data = curl_exec($ch); curl_close($ch); return $data; }else{ return '请先安装curl'; }}$post_string为数组,如array("a"=>1)5curl扩展函数也用于get方式请求数据6查看curl是否安装,php**()
end 20210311