mechta-market/php-http-client

此包的最新版本(1.0.2)没有可用的许可信息。

1.0.2 2024-09-04 10:09 UTC

This package is auto-updated.

Last update: 2024-09-04 10:10:48 UTC


README

GitHub Actions Workflow Status Packagist Downloads

安装

composer require mechta-market/php-http-client

示例

GET 请求

$httpClient = new HttpClient();
$response = $httpClient->get("example.org");

var_dump($response->successful());

带参数的 GET 请求

$httpClient = new HttpClient();
$httpClient->withQueryParameters(["foo" => "bar", "test" => "value"]);
$response = $httpClient->get("example.org");

var_dump($response->successful());

POST 请求

$httpClient = new HttpClient();
$data = ["foo" => "bar"];
$response = $httpClient->post("example.org", $data);

var_dump($response->successful());

带 body 的 POST 请求

$httpClient = new HttpClient();
$data = ["foo" => "bar"];
$httpClient->withBody($data);

$response = $httpClient->post("example.org");

Bearer 令牌

$httpClient = new HttpClient();
$httpClient->withToken("random_string_token_value");

$response = $httpClient->get("example.org");

基本认证

$httpClient = new HttpClient();
$httpClient->withBasicAuth("user", "random_string_token_value");

$response = $httpClient->get("example.org");