- 场景,很多时候项目中会使用第三方接口,虽然有curl方式已经很强大,但是对于我们自己去一个个编写还是非常大的难度的
- 这里使用GuzzleHttp插件进行接口请求
安装
composer require guzzlehttp/guzzle
我们以一个登陆的post的接口为例:
$client =new \GuzzleHttp\Client();
$res = $client->request('POST','XXXXX',['form_params'=>['name'=>'test','password'=>'123456']]);
return $res->getBody();
结果:
更多请求方法查看文档:http://docs.guzzlephp.org/en/stable/index.html