file_get_contents()对指定网页或API实现get+post请求并传输获取数据
//GET请求方法 $url="https://www.baidu.com"; $ret=file_get_contents($url); $list = json_decode($ret,1); //把json转为数组格式,视个人情况转换
//POST和GET通用请求方法 $url="https://www.baidu.com"; $data = ['username' => '***','password' => '***']; $data = json_encode($data); $opts = [ 'http' => [ 'method' => 'POST', 'header' => 'Content-type:application/json', 'content' => $data, ] ]; $context = stream_context_create($opts); $ret = file_get_contents($url,false,$context);