900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Laravel6.* 使用Guzzle执行HTTP请求

Laravel6.* 使用Guzzle执行HTTP请求

时间:2023-09-28 17:04:31

相关推荐

Laravel6.* 使用Guzzle执行HTTP请求

安装

使用composer安装:

composer require guzzlehttp/guzzle

或者编辑项目的composer.json文件,添加guzzle作为依赖:

"require": {...."guzzlehttp/guzzle": "~6.0"},

然后执行composer update

二、guzzle基本使用

发送请求

use GuzzleHttp\Client;$client = new Client([//跟域名'base_uri' => 'http://localhost/test',// 超时'timeout' => 2.0,]);$response = $client->get('/get'); //http://localhost/get$response = $client->delete('delete'); //http://localhost/get/delete$response = $client->head('http://localhost/get');$response = $client->options('http://localhost/get');$response = $client->patch('http://localhost/patch');$response = $client->post('http://localhost/post');$response = $client->put('http://localhost/put');

post

$response = $client->request('POST', 'http://localhost/post', ['form_params' => ['username' => 'webben','password' => '123456','multiple' => ['row1' => 'hello']]]);

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