darkphp/monster 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

darkphp/monster

最新稳定版本:1.0.8

Composer 安装命令:

composer require darkphp/monster

包简介

A simple PHP class for making HTTP requests using cURL

README 文档

README

HTTPMonster is a PHP class that provides a simple and easy-to-use interface for making HTTP requests using cURL. It allows you to easily set HTTP headers, request body, request method, and other options.

Installation

You can install HTTPMonster using Composer:

composer require darkphp/monster

Usage

To use HTTPMonster, you first need to create an instance of the class:

require_once 'vendor/autoload.php';

use DarkPHP\HTTPMonster;

$http = new HTTPMonster();

Setting Request Options

HTTPMonster provides several methods for setting request options:

$http->Url('https://example.com');
$http->Method('POST');
$http->Headers([
    'Content-Type: application/json',
    'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX'
]);
$http->Body('{"foo": "bar"}');
$http->Timeout(30);
echo $http->getBody();

Sending the Request

To send the request, simply call the Send() method:

$response = $http->Send();

The Send() method returns the response from the server as a string.

Getting the HTTP Status Code

You can get the HTTP status code of the response using the getStatus() method:

$status = $http->getStatus();

Add 1 Option

HTTPMonster add cURL options for the request. You can modify these defaults by calling the Option() method:

$http->Option(CURLOPT_RETURNTRANSFER, true);

Chaining Methods

HTTPMonster allows you to chain methods to make the code more readable:

$response = $http->Url('https://example.com')
    ->Method('POST')
    ->Headers([
        'Content-Type: application/json',
        'Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXX'
    ])
    ->Body('{"foo": "bar"}')
    ->Timeout(30)
    ->Send();

Error Handling

HTTPMonster throws an exception if cURL encounters an error while executing the request. You should always catch these exceptions to handle errors properly:

try {
    $response = $http->Send();
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

License

HTTPMonster is licensed under the MIT License. See LICENSE for more information.

Developer

HTTPMonster is developed by Hossein Pira.

If you have any questions, comments, or feedback, please feel free to contact John via email or Telegram.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固