定制 nextstage-brasil/ns-http 二次开发

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

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

nextstage-brasil/ns-http

最新稳定版本:1.0.0

Composer 安装命令:

composer require nextstage-brasil/ns-http

包简介

Methods and classes for various utilities

README 文档

README

vendor/bin/phpunit

The Http class encapsulates HTTP calls using cURL in PHP. It supports various HTTP methods such as GET, POST, PUT, and DELETE, and allows the configuration of headers, parameters, and SSL options.

Methods

call

Makes an HTTP call to a specified URL.

Parameters

  • string $url: The URL to which the request will be made.
  • array $params: Request parameters (optional, default: []).
  • string $method: HTTP method (GET, POST, PUT, DELETE, etc.) (optional, default: 'GET').
  • array $header: HTTP headers (optional, default: ['Content-Type: application/json']).
  • bool $ssl: Verify SSL (optional, default: true).
  • int $timeout: Request timeout in seconds (optional, default: 30).

Return

  • Response: An object containing the response of the request, including:
    • body: Response content.
    • error_code: cURL error code.
    • error: cURL error message.
    • http_code: HTTP status code.
    • headers: Response headers.
    • url: Effective request URL.

Example Usage

// URL for the request
$url = 'https://api.example.com/data';

// Request parameters
$params = [
    'key' => 'value',
    'another_param' => 'another_value'
];

// Request headers
$headers = [
    'Content-Type: application/json',
    'Authorization: Bearer your_token_here'
];

$response = Http::call($url, $params, 'GET', $headers);

// Accessing the response
echo $response->getBody(); // Response content
echo $response->getBodyAsObject(); // Response content as JSON Object
echo $response->getBodyAsArray(); // Response content as JSON Array
echo $response->getHttpCode(); // HTTP status code

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-09-08