200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > php 使用guzzle发送异步的HTTP请求

php 使用guzzle发送异步的HTTP请求

时间:2022-06-23 15:07:04

相关推荐

php 使用guzzle发送异步的HTTP请求

安装使用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]);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。