定制 lucasarend/http-fox 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lucasarend/http-fox

最新稳定版本:v1.0.10

Composer 安装命令:

composer require lucasarend/http-fox

包简介

This pacote is basic to use curl

README 文档

README

HttpFox is a PHP wrapper around cURL that simplifies HTTP requests like GET, POST, PUT, and DELETE. It provides easy cookie management, user-agent configuration, support for proxy and SSL certificates, and convenient file-size retrieval.

Features

✅ Easy GET, POST, PUT, PATCH and DELETE requests
✅ Built-in cookie management with optional file storage
✅ Custom User-Agent support
✅ Proxy support (with or without authentication)
✅ SSL certificate support (PFX and PEM)
✅ Get remote file sizes in different units (B, KB, MB, GB)
✅ Set request timeouts and low-speed limits
✅ Enable or disable verbose cURL output

Installation

Use Composer:

composer require lucasarend/httpfox

Usage

use LucasArend\HttpFox\HttpFox;

$httpFox = new HttpFox();

// GET request
$response = $httpFox->getURL('https://example.com');
echo $response;

// POST request
$postData = ['name' => 'John', 'email' => 'john@example.com'];
$response = $httpFox->sendPost('https://example.com/api', $postData);

// Enable or disable cookie files
$httpFox->useCookieFile(true);

// Set a custom cookie directory
$httpFox->setCookiePath('/path/to/cookies');

// Set proxy
$httpFox->setProxy('127.0.0.1', 8080, 'username', 'password');

// Disable SSL verification (not recommended in production)
$httpFox->disableSSL(true);

// Set a PFX certificate
try {
    $httpFox->setPFX('/path/to/certificate.pfx', 'password');
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

// Set custom headers
$httpFox->setHeaders([
    'Authorization: Bearer your_token',
    'Accept: application/json'
]);

API Reference

Method Description
getURL($url) Makes a GET request.
sendPost($url, $data) Makes a POST request with data.
sendPUT($url, $data) Makes a PUT request with data.
sendDELETE($url, $data) Makes a DELETE request with data.
setCookiePath($path) Sets the directory for cookie files.
useCookieFile($bool) Enables or disables cookie file usage.
setProxy($host, $port, $user, $password) Sets up a proxy server.
disableSSL($bool) Enables or disables SSL certificate verification.
setPFX($path, $password) Sets a PFX certificate.
setPEM($path, $password) Sets a PEM certificate.
setHeaders($headers) Sets custom HTTP headers.
setUserAgent($ua) Sets a custom User-Agent.
setTimeOut($seconds) Sets request timeout in seconds.
setConnectTimeout($seconds) Sets connection timeout in seconds.
get_file_size($url, $unit) Gets the remote file size in bytes, KB, MB, or GB.

License

MIT

统计信息

  • 总下载量: 7.75k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-16