PHPackages                             webguosai/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. [HTTP &amp; Networking](/categories/http)
4. /
5. webguosai/http-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

webguosai/http-client
=====================

http客户端

v2.2.4(2y ago)04722MITPHPPHP &gt;=5.6

Since Feb 15Pushed 2y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (20)Used By (2)

http client
===========

[](#http-client)

[![Latest Stable Version](https://camo.githubusercontent.com/76c1951424c99b1200bb7cb7e8bf3a98461b64f48f5a59325cbd9f4622da756f/68747470733a2f2f706f7365722e707567782e6f72672f77656267756f7361692f687474702d636c69656e742f762f737461626c65)](https://packagist.org/packages/webguosai/http-client)[![Total Downloads](https://camo.githubusercontent.com/eade6a5158f19a02eb4b91c8d315706b48ad82bbe5e76a6d194f3fb2ed487cef/68747470733a2f2f706f7365722e707567782e6f72672f77656267756f7361692f687474702d636c69656e742f646f776e6c6f616473)](https://packagist.org/packages/webguosai/http-client)[![Latest Unstable Version](https://camo.githubusercontent.com/482b8071ac118489457a060c97ccad746a18fcf744118ab3ecc43993d8fb69ef/68747470733a2f2f706f7365722e707567782e6f72672f77656267756f7361692f687474702d636c69656e742f762f756e737461626c65)](https://packagist.org/packages/webguosai/http-client)[![License](https://camo.githubusercontent.com/844e8e64dd9779a3f9ad3b020a666a9e8e84a630886131b6961d2df4dfafd9d6/68747470733a2f2f706f7365722e707567782e6f72672f77656267756f7361692f687474702d636c69656e742f6c6963656e7365)](https://packagist.org/packages/webguosai/http-client)

运行环境
----

[](#运行环境)

- php &gt;= 5.6
- composer

安装
--

[](#安装)

```
composer require webguosai/http-client -vvv
```

使用
--

[](#使用)

### 初始化

[](#初始化)

```
$options = [
    //超时(单位秒)
    'timeout'     => 3,

    //代理ip池(允许填写多个,会随机使用一组)
    'useSocks5'   => true, // 使用 socks5 代理
    'proxyIps'    => [
        //格式为【ip:端口】
        '0.0.0.0:8888'
    ],

    //重定向、及最多重定向跳转次数
    'redirects'   => false,
    'maxRedirect' => 5,

    //cookie自动保存路径
    'cookieJarFile' => 'cookie.txt',

    //ca证书路径
    'caFile'        => __DIR__.'/cacert/cacert.pem',
];
$http = new \Webguosai\HttpClient($options);
```

### 请求

[](#请求)

```
$headers = [
    'User-Agent' => 'http-client browser',
    'cookie' => 'login=true'
];
$data = ['data' => '111', 'data2' => '222'];

//所有方法
$response = $http->get($url, $data, $headers);
$response = $http->post($url, $data, $headers);
$response = $http->put($url, $data, $headers);
$response = $http->patch($url, $data, $headers);
$response = $http->delete($url, $data, $headers);
$response = $http->head($url, $data, $headers);
$response = $http->options($url, $data, $headers);
```

### 响应

[](#响应)

```
$response->request; //请求
$response->headers; //响应头
$response->body; //响应body
$response->httpStatus; //http状态码
$response->contentType; //内容类型
$response->info; //其它信息
$response->info['url'];//最终请求的地址
$response->getHtml(); //获取html
$response->getChatset(); //编码
$response->json(); //json
$response->xml(); //xml
$response->ok();//http=200返回真
$response->getErrorMsg(); //错误信息
```

### data 传值方式

[](#data-传值方式)

```
// multipart/form-data
$data = ['data' => '111', 'data2' => '222'];

// application/x-www-form-urlencoded
$data = http_build_query($data);

// application/json
$data = json_encode($data);

// 文件上传 $_FILES['file'] 接收
$data = [
    'file' => new \CURLFile('1.jpg'),
];

$response = $http->post($url, $data);
```

### headers 传值方式

[](#headers-传值方式)

```
//数组传递
$headers = [
    'User-Agent: chrome',
    'User-Agent' => 'chrome',
];

//纯字符串 (一般为从浏览器复制)
$headers = 'User-Agent: chrome
Referer: https://www.x.com
Cookie: cookie=6666666';

$response = $http->post($url, $data, $headers);
```

实操
--

[](#实操)

```
$options = [
    'timeout'   => 3,
];
$http    = new \Webguosai\HttpClient($options);
$response = $http->get('http://www.baidu.com');
if ($response->ok()) {
    var_dump($response->body);
    //var_dump($response->json());
} else {
    var_dump($response->getErrorMsg());
}
```

打赏
--

[](#打赏)

 [![](https://camo.githubusercontent.com/49674a436947352122e2d23e49c3324b8dd4a413b414e45849def0667483cbef/68747470733a2f2f7778342e73696e61696d672e636e2f6d77313032342f303038766f44783367793168366c31617a707779736a333075303134777439682e6a7067)](https://camo.githubusercontent.com/49674a436947352122e2d23e49c3324b8dd4a413b414e45849def0667483cbef/68747470733a2f2f7778342e73696e61696d672e636e2f6d77313032342f303038766f44783367793168366c31617a707779736a333075303134777439682e6a7067) [![](https://camo.githubusercontent.com/04e0e05cdd7e51a95a1c2a13838d166ccdb6244a36b9db51b29d7e0c8f75539a/68747470733a2f2f7778322e73696e61696d672e636e2f6d77313032342f303038766f44783367793168366c31617a703576686a3330753031616f6164632e6a7067)](https://camo.githubusercontent.com/04e0e05cdd7e51a95a1c2a13838d166ccdb6244a36b9db51b29d7e0c8f75539a/68747470733a2f2f7778322e73696e61696d672e636e2f6d77313032342f303038766f44783367793168366c31617a703576686a3330753031616f6164632e6a7067)

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~47 days

Recently: every ~127 days

Total

19

Last Release

1063d ago

Major Versions

1.1 → v2.0.02021-11-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/79b27387fc59b6ba29854bad71e11e6f7269534da234243353c5ec876bf9af5a?d=identicon)[json.](/maintainers/json.)

---

Top Contributors

[![webguosai](https://avatars.githubusercontent.com/u/2083784?v=4)](https://github.com/webguosai "webguosai (50 commits)")

---

Tags

httphttp-clientphphttphttpclient

### Embed Badge

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

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

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.1k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B5.5k](/packages/psr-http-message)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[psr/http-client

Common interface for HTTP clients

1.7k680.7M2.1k](/packages/psr-http-client)[psr/link

Common interfaces for HTTP links

2.5k144.1M69](/packages/psr-link)[rmccue/requests

A HTTP library written in PHP, for human beings.

3.6k34.5M253](/packages/rmccue-requests)

PHPackages © 2026

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