PHPackages                             gaoming13/http-curl - 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. gaoming13/http-curl

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

gaoming13/http-curl
===================

Curl模拟Http工具类

2.3.2(5y ago)22423↓100%22[1 issues](https://github.com/gaoming13/HttpCurl/issues)1MITPHPPHP &gt;=5.3

Since Mar 10Pushed 5y ago4 watchersCompare

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

READMEChangelog (7)DependenciesVersions (8)Used By (1)

HttpCurl.class.php
==================

[](#httpcurlclassphp)

[![Latest Stable Version](https://camo.githubusercontent.com/afe25058e83ca8271e4a9af84727f22b6158132c97c28edaed46681a6d3f3d85/68747470733a2f2f706f7365722e707567782e6f72672f67616f6d696e6731332f687474702d6375726c2f762f737461626c652e737667)](https://packagist.org/packages/gaoming13/http-curl)[![Total Downloads](https://camo.githubusercontent.com/b7f0a63c6be145694e6179629045d62b832a94774d2e04fac2d187659f9e8070/68747470733a2f2f706f7365722e707567782e6f72672f67616f6d696e6731332f687474702d6375726c2f646f776e6c6f616473)](https://packagist.org/packages/gaoming13/http-curl)

Curl模拟Http工具类

- 可实现模拟GET、POST请求, 支持上传文件/自定义header头
- 支持 5.3+

How To Use.
-----------

[](#how-to-use)

使用composer

```
composer require gaoming13/http-curl
```

```
use Gaoming13\HttpCurl\HttpCurl;
```

### 示例

[](#示例)

```
// 普通GET
// curl 'http://example.com/'
$res = HttpCurl::request('http://example.com/', 'get');
```

```
// GET带参数
// curl 'http://example.com/?a=123&b=456'
$res = HttpCurl::request('http://example.com/?a=123', 'get', array(
  'b' => '456'
));
```

```
// POST Form-Data(Form Data)
// curl 'http://example.com/?ac=login' \
//  --data-raw 'username=root&password=123456'
$res = HttpCurl::request('http://example.com/?ac=login', 'post', array(
    'username' => 'root',
    'password' => '123456'
));
```

```
// POST RAW(Request Payload)
// curl 'http://example.com/?ac=login' \
//  --data-binary '{"username":"root","password":"123456"}'
$res = HttpCurl::request('http://example.com/?ac=login', 'post', '{"username":"root","password":"123456"}', [
	'Content-Type:application/json'
]);
```

```
// POST 上传图片
$res = HttpCurl::request('http://example.com/', 'post', array(
  'file1' => '@/data/sky.jpg',
  'file2' => '@/data/bird.jpg'
), [
  'Content-Type: image/jpeg'
]);

$res = HttpCurl::request('http://example.com/', 'post', array(
  'file1' => '@G:\wamp\www\data\sky.jpg',
  'file2' => '@G:\wamp\www\data\bird.jpg'
));
```

```
list($body, $header, $status, $errno, $error) =
  HttpCurl::request(
    // 请求地址
    'http://example.com/',
    // 请求方式(post/get)
    'get',
    // 传递的参数(get为queryString, post为Request Payload)
    array(
      'username' => 'root',
      'password' => '123456'
    ),
    // 请求头(cookie写在这里)
    [
      'Accept: text/plain, */*; q=0.01',
      'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
      'Referer: https://www.baidu.com/',
      'Cookie: BD_UPN=123253; PSTM=1592901563;'
    ],
    // 超时时间(秒)
    5
  );

// 响应正文(string)(获取失败返回空字符串)
var_dump($body);
// 响应头(string)(原始格式)
var_dump($header);
// 响应状态(array)(数组)
var_dump($status);
// 错误码(int)(0表示正常响应)
// 其它错误码见：https://www.php.net/manual/zh/function.curl-errno.php
var_dump($errno);
```

$body 响应正文

```

    Example Domain
  ...

```

$header 响应头

```
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Thu, 14 Apr 2016 08:42:35 GMT
Etag: "359670651+gzip"
Expires: Thu, 21 Apr 2016 08:42:35 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (rhv/818F)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 1270

```

$status 该次请求的状态

```
'url' => string 'http://www.example.com/' (length=23)
'content_type' => string 'text/html' (length=9)
'http_code' => int 200
'header_size' => int 349
'request_size' => int 54
'filetime' => int -1
'ssl_verify_result' => int 0
'redirect_count' => int 0
'total_time' => float 0.512924
'namelookup_time' => float 0.064248
'connect_time' => float 0.270048
'pretransfer_time' => float 0.270202
'size_upload' => float 0
'size_download' => float 1270
'speed_download' => float 2476
'speed_upload' => float 0
'download_content_length' => float 1270
'upload_content_length' => float 0
'starttransfer_time' => float 0.510861
'redirect_time' => float 0
'redirect_url' => string '' (length=0)
'primary_ip' => string '93.184.216.34' (length=13)
'certinfo' =>
array (size=0)
  empty
'primary_port' => int 80
'local_ip' => string '192.168.248.129' (length=15)
'local_port' => int 54402

```

$errno 错误码

```
0

```

$error 错误信息

```

```

### v1

[](#v1)

```
require 'v1/HttpCurl.class.php';

// GET请求
HttpCurl::get('http://api.example.com/');

// GET请求, 并json_decode返回的数组
HttpCurl::get('http://api.example.com/?a=123&b=456', 'json');

// POST请求
HttpCurl::post('http://api.example.com/?a=123', array(
  'abc'=>'123',
  'efg'=>'567'
));
HttpCurl::post('http://api.example.com/', '这是post原始内容', 'json');

// POST请求, 文件上传
HttpCurl::post('http://api.example.com/', array(
  'file1'=>'@/data/sky.jpg',
  'file2'=>'@/data/bird.jpg',
));
```

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~391 days

Total

7

Last Release

2144d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/29424726113009448b05ad62b72c3bd3701ec312166a676b09ed34fe2f878358?d=identicon)[gaoming13](/maintainers/gaoming13)

---

Top Contributors

[![gaoming13](https://avatars.githubusercontent.com/u/11879869?v=4)](https://github.com/gaoming13 "gaoming13 (21 commits)")

---

Tags

php-curl

### Embed Badge

![Health badge](/badges/gaoming13-http-curl/health.svg)

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M317](/packages/friendsofsymfony-rest-bundle)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48247.0M382](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

83510.1M71](/packages/smi2-phpclickhouse)[geocoder-php/common-http

Common files for HTTP based Geocoders

18722.1M64](/packages/geocoder-php-common-http)[illuminate/http

The Illuminate Http package.

11936.0M5.0k](/packages/illuminate-http)

PHPackages © 2026

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