programster/guzzle-wrapper

一个库,用于简化使用Guzzle发送HTTP请求。

1.1.0 2020-12-28 17:11 UTC

This package is auto-updated.

Last update: 2024-09-05 17:34:58 UTC


README

一个围绕Guzzle的库,以便更容易发送HTTP请求。如果您需要做更复杂的事情,则可以在其中获取Guzzle对象。

示例用法

$request = new Programster\GuzzleWrapper\Request(
    Programster\GuzzleWrapper\Method::createGet(),
    'http://my.domain.com',
    ['hello' => 'world']
);

// send the request to get a response
$response = $request->send();

// If we were sending to an API, then we want to json_decode the response
$jsonResponseObject = json_decode($response->getBody());

切换到POST/PUT/DELETE只需一行代码。例如:

$request = new Programster\GuzzleWrapper\Request(
    Programster\GuzzleWrapper\Method::createPost(),
    'http://my.domain.com',
    ['hello' => 'world']
);

测试

进入测试文件夹并运行:

php -S localhost:80 RequestDumper.php

然后使用以下命令执行测试:

php main.php

这将简单地告诉您每个测试是否通过。