alimranahmed / easyhttp
此包已被废弃,不再维护。未建议替代包。
laravel 的简单 Http 客户端
1.0.1
2019-05-29 13:35 UTC
Requires
- php: ^7.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2023-04-15 21:56:12 UTC
README
轻松发起 Http 请求,并在 Laravel 的默认日志(/storage/logs)中记录请求和响应。
这是一个 Laravel 5 HTTP 客户端包,旨在简化 HTTP 请求。它是基于 Guzzle HTTP 客户端和 cURL 的封装,简化了常见请求。我们可以在本包运行时使用 Guzzle 或 cURL。
安装
在您的项目目录根目录下运行以下命令
composer require alimranahmed/easyhttp
这就完成了!
用法
默认情况下,所有请求都是使用 Guzzle 发起的。
<?php //For GET request $response = Http::get('www.example.com/get'); //For POST Request $data = ['key' => 'value']; $headers = ['Content-Type' => 'application/json']; $response = Http::post('www.example.com/post', $data, $headers); //For PUT request $data = ['key' => 'value']; $headers = ['Content-Type' => 'application/json']; $response = Http::put('www.example.com/put', $data, $headers); //For DELETE request $response = Http::delete('www.example.com/delete'); //To Retrieve the response status, header and body $response->getStatusCode(); //for status code $response->getHeaders(); //for headers $response->contents; //for body
要使用 cURL 发起任何请求,我们可以简单地使用以下 using()
方法
<?php Http::using('curl')->get('www.example.com/get');