GuzzleHttp

简介

HTTP默认集成了GuzzleHttp,这是一个非常好用的http请求封装库,当我们有需要actionphp内请求其他资源是可以使用此工具。

安装扩展

InitAdmin内置无需安装

基本用法

get请求接口http://127.0.0.1:8080/apiurl

  1. $client = new \GuzzleHttp\Client([
  2. 'base_uri' => 'http://127.0.0.1:8080',
  3. 'timeout' => 2.0,
  4. ]);
  5. $response1 = json_decode(
  6. $client->request('GET', '/apiurl', [
  7. 'headers' => [
  8. 'Authorization' => $response['data']
  9. ]
  10. ]),
  11. true);
  12. var_dump($response):

中文文档地址

https://guzzle-cn.readthedocs.io