PHPackages                             easyswoole/http-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. easyswoole/http-client

ActiveLibrary[Framework](/categories/framework)

easyswoole/http-client
======================

php stander lib

1.6.1(3y ago)895.4k↓22.7%15[1 PRs](https://github.com/easy-swoole/http-client/pulls)20Apache-2.0PHPPHP &gt;=7.1.0

Since Dec 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/easy-swoole/http-client)[ Packagist](https://packagist.org/packages/easyswoole/http-client)[ Docs](https://www.easyswoole.com/)[ RSS](/packages/easyswoole-http-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (43)Used By (20)

协程HttpClient
============

[](#协程httpclient)

安装
--

[](#安装)

```
composer require easyswoole/http-client

```

单元测试
----

[](#单元测试)

```
./vendor/bin/co-phpunit tests/

```

示例代码
----

[](#示例代码)

```
namespace EasySwoole\HttpClient\Test;

use EasySwoole\HttpClient\HttpClient;
use PHPUnit\Framework\TestCase;

class Test extends TestCase
{
    /*
     * url内容请看 tests/index.php
     */
    private $url = 'http://docker.local.com/index.php?arg1=1&arg2=2';

    function testGet()
    {
        $client = new HttpClient($this->url);
        $response = $client->get();
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("GET",$json['REQUEST_METHOD']);
        $this->assertEquals([],$json['POST']);
        $this->assertEquals(['arg1'=>1,'arg2'=>2],$json['GET']);
    }

    function testOptions()
    {
        $client = new HttpClient($this->url);
        $response = $client->options(['op'=>'op1'],['head'=>'head']);
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("OPTIONS",$json['REQUEST_METHOD']);
        $this->assertEquals("head",$json['HEADER']['head']);
    }

    function testPost()
    {
        $client = new HttpClient($this->url);
        $response = $client->post([
            'post1'=>'post1'
        ]);
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("POST",$json['REQUEST_METHOD']);
        $this->assertEquals([ 'post1'=>'post1'],$json['POST']);
        $this->assertEquals(['arg1'=>1,'arg2'=>2],$json['GET']);
    }

    function testPostString()
    {
        $client = new HttpClient($this->url);
        $response = $client->post('postStr');
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("POST",$json['REQUEST_METHOD']);
        $this->assertEquals([],$json['POST']);
        $this->assertEquals('postStr',$json['RAW']);
    }

    function testPostJson()
    {
        $client = new HttpClient($this->url);
        $response = $client->postJson(json_encode(['json'=>'json1']));
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("POST",$json['REQUEST_METHOD']);
        $this->assertEquals([],$json['POST']);
        $this->assertEquals(['arg1'=>1,'arg2'=>2],$json['GET']);
        $raw = $json["RAW"];
        $raw = json_decode($raw,true);
        $this->assertEquals(['json'=>'json1'],$raw);
    }

    function testPostFile()
    {
        $client = new HttpClient($this->url);
        $response = $client->post([
            'post1'=>'post1',
            'file'=> new \CURLFile(__FILE__)
        ]);
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("POST",$json['REQUEST_METHOD']);
        $this->assertEquals([ 'post1'=>'post1'],$json['POST']);
        $this->assertEquals(['arg1'=>1,'arg2'=>2],$json['GET']);
        $this->assertEquals('Test.php',$json['FILE']['file']['name']);
    }

    function testCookies()
    {
        $client = new HttpClient($this->url);
        $client->addCookies([
            'cookie1'=>'cook'
        ]);
        $response = $client->get(['head'=>'head']);
        $json = json_decode($response->getBody(),true);
        $this->assertEquals("GET",$json['REQUEST_METHOD']);
        $this->assertEquals("head",$json['HEADER']['head']);
        $this->assertEquals("cook",$json['COOKIE']['cookie1']);
    }

    function testPostXml()
    {
        $client = new HttpClient($this->url);
        $response = $client->postXml('');
        $json = json_decode($response->getBody(),true);
        $this->assertEquals('',$json['RAW']);
    }
}

```

支持方法
----

[](#支持方法)

- \_\_construct
- setUrl
- setEnableSSL
- setTimeout
- setConnectTimeout
- setKeepAlive
- setSslVerifyPeer
- setSslHostName
- setSslCafile
- setSslCapath
- setSslCertFile
- setSslKeyFile
- setProxyHttp
- setProxySocks5
- setSocketBind
- setClientSetting
- setClientSettings
- getClient
- setMethod
- setXMLHttpRequest
- setContentTypeJson
- setContentTypeXml
- setContentTypeFormData
- setContentTypeFormUrlencoded
- setContentType
- get
- head
- trace
- delete
- put
- post
- patch
- options
- postXml
- postJson
- download
- setHeaders
- setHeader
- addCookies
- addCookie
- upgrade
- push
- recv
- \_\_destruct

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community33

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~37 days

Recently: every ~239 days

Total

42

Last Release

1169d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/45c234d5f129ea570e630425636299127647534f0c2cbb073555e2c45d403d6f?d=identicon)[kiss291323003](/maintainers/kiss291323003)

---

Top Contributors

[![kiss291323003](https://avatars.githubusercontent.com/u/24490609?v=4)](https://github.com/kiss291323003 "kiss291323003 (47 commits)")[![Player626](https://avatars.githubusercontent.com/u/44792981?v=4)](https://github.com/Player626 "Player626 (24 commits)")[![evalor](https://avatars.githubusercontent.com/u/26944445?v=4)](https://github.com/evalor "evalor (11 commits)")[![tioncico](https://avatars.githubusercontent.com/u/31308307?v=4)](https://github.com/tioncico "tioncico (7 commits)")[![RunsTp](https://avatars.githubusercontent.com/u/28254581?v=4)](https://github.com/RunsTp "RunsTp (3 commits)")[![shamo88](https://avatars.githubusercontent.com/u/20869654?v=4)](https://github.com/shamo88 "shamo88 (1 commits)")[![xuanyanwow](https://avatars.githubusercontent.com/u/28777109?v=4)](https://github.com/xuanyanwow "xuanyanwow (1 commits)")[![giantwu](https://avatars.githubusercontent.com/u/1921408?v=4)](https://github.com/giantwu "giantwu (1 commits)")[![huizhang001](https://avatars.githubusercontent.com/u/26496638?v=4)](https://github.com/huizhang001 "huizhang001 (1 commits)")[![LiHangMaiK](https://avatars.githubusercontent.com/u/20616136?v=4)](https://github.com/LiHangMaiK "LiHangMaiK (1 commits)")[![LuffyQAQ](https://avatars.githubusercontent.com/u/35624300?v=4)](https://github.com/LuffyQAQ "LuffyQAQ (1 commits)")

---

Tags

asyncframeworkswooleeasyswoole

### Embed Badge

![Health badge](/badges/easyswoole-http-client/health.svg)

```
[![Health](https://phpackages.com/badges/easyswoole-http-client/health.svg)](https://phpackages.com/packages/easyswoole-http-client)
```

###  Alternatives

[easyswoole/easyswoole

An efficient swoole framework

4.8k186.9k50](/packages/easyswoole-easyswoole)[easyswoole/mysqli

An efficient swoole framework

34120.5k27](/packages/easyswoole-mysqli)[easyswoole/redis

easyswoole component

3391.8k12](/packages/easyswoole-redis)[easyswoole/kafka

An efficient swoole framework

4211.1k](/packages/easyswoole-kafka)[easyswoole/compiler

easyswoole component

691.1k](/packages/easyswoole-compiler)[easyswoole/fast-cache

An efficient swoole framework

1030.3k2](/packages/easyswoole-fast-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
