安装使用composer
composer require guzzlehttp/guzzle
代码式例
use GuzzleHttp\Client;use GuzzleHttp\Exception\RequestException;public function index(){$client = Client();$data = ['name'=>'小花','age'=>12];$url = 'http://gadeas.top/api/dome';// 发送一个异步请求$promise = $client->request("GET",$url,["query"=>$data]);// $promise->wait();//阻塞}
概述 — Guzzle中文文档 (guzzle-cn.readthedocs.io)
https请求问题
https** 报错(cURL error 60)
1.找到Client/configureDefaults()把 ‘verify’ 改成 false,就可以了
直接在代码中修改配置
$client = new Client(['timeout' => 5, 'verify' => false]);$data = ['name'=>'小花','age'=>12];$url = 'https://gadeas.top/api/dome';// 发送一个异步请求$promise = $client->request("POST",$url,["query"=>$data]);