yvesnda/simple_http
最新稳定版本:v1.0.0
Composer 安装命令:
composer require yvesnda/simple_http
包简介
README 文档
README
A simple PHP HTTP library with a single helper function for making HTTP requests.
Installation
Install via Composer:
composer require yvesnda/simple_http
Usage
The library provides a single function: http_request.
require 'vendor/autoload.php'; // Example GET request $response = http_request('GET', 'https://api.example.com/data'); // Example POST request with JSON data $response = http_request('POST', 'https://api.example.com/data', [], ['key' => 'value']); // Access response details if ($response['error']) { echo "Error: " . $response['error']; } else { echo "HTTP Code: " . $response['code'] . PHP_EOL; print_r($response['result']); }
Function Signature
http_request($method, $url, $headers = [], $data = '', $follow_response_type = 1)
- $method: HTTP method (
GET,POST,PUT,PATCH,DELETE) - $url: Request URL
- $headers: (optional) Array of headers
- $data: (optional) Array or string of data to send
- $follow_response_type: (optional) If
1, tries to decode JSON/XML responses
Response Structure
The function returns an array with:
code: HTTP status codeheaders: Request headers sentraw: Raw response bodyresult: Parsed response (array for JSON, SimpleXMLElement for XML, or raw string)error: Error message if any
License
MIT License. See LICENSE.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-07