- 場景,很多時候項目中會使用第三方接口,雖然有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