Laravel ——GuzzleHttp 使用方法(自用)

本文介绍了如何在 Laravel 中使用 GuzzleHttp,一个PHP HTTP客户端,用于简化HTTP请求和Web服务交互。内容涵盖了发送请求、POST操作、设置自定义header以及处理cookie。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Guzzle

Guzzle 是一个 PHP HTTP 客户端,致力于让发送 HTTP 请求以及与 Web 服务进行交互变得简单。 
Github:https://github.com/guzzle/guzzle 
Composer:https://packagist.org/packages/guzzlehttp/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');
$resp
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值