在这里我想说一下,本章旨在学习,无任何越权操作!都是在thinkphp5的环境下,本地环境localhost
通过composer安装完成Guzzle之后,引入
1 | use GuzzleHttp\Client; |
1 2 3 4 5 6 7 8 9 10 11 12 13 | $client = new Client(); $url = 'http://www.xxxxxxx.cn/api/getData?params=www.xxxxx.cn'; //在这一步,headers里面的参数,类似于伪造访问ip(不知道这样说对不对),相关配置详见Guzzle文档 https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html#headers $response = $client->request('GET', $url, [ 'headers' => [ 'x-forwarded-for' => 'xxx.xxx.xxx.xxx' ] ])->getBody()->getContents(); $data = json_decode($response, true); dump($data);exit; $this->assign('content', $data); return $this->view->fetch('other'); |
至此便能得到相应接口的数据!