xin/http

基于 guzzlehttp/guzzle 实现的一个轻量级的Http客户端。

v1.3.0 2025-04-02 09:32 UTC

This package is auto-updated.

Last update: 2025-04-02 12:31:13 UTC


README

介绍

基于 guzzlehttp/guzzle 实现的一个轻量级的Http客户端。

软件架构

软件架构说明

安装教程

composer require xin/http

使用说明

基础用法
<?php
Xin\Http\Client::get($url, $data = null, $options = []);
Xin\Http\Client::post($url, $data = null, $options = []);
Xin\Http\Client::postJSON($url, $data = null, $options = []);
Xin\Http\Client::put($url, $data = null, $options = []);
Xin\Http\Client::delete($url, $data = null, $options = []);
Xin\Http\Client::upload($url, $data = null, $options = []);
完整用法
<?php

use Xin\HttpClient\HttpClient;
use Xin\HttpClient\Interceptors\Requests\BodyJsonParametersInterceptor;
use Xin\HttpClient\Interceptors\Responses\DecodedInterceptor;

require_once 'vendor/autoload.php';

HttpClient::instance()->mergeOptions([
	'timeout' => 1,
]);

$response = HttpClient::get('https://www.baidu.com');
var_dump("is successful:" . $response->successful());
var_dump("contents:", $response->json());

$response = HttpClient::post('https://www.baidu.com');
var_dump("is successful:" . $response->successful());
var_dump("contents:", $response->body());


var_dump(HttpClient::default()->getOptions());
HttpClient::default()->addRequestInterceptor(new BodyJsonParametersInterceptor());
HttpClient::default()->addResponseInterceptor(new DecodedInterceptor());
$response = HttpClient::get('https://laravel-app.test.com/api');
var_dump($response);