定制 aportela/httprequest-wrapper 二次开发

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

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

aportela/httprequest-wrapper

Composer 安装命令:

composer require aportela/httprequest-wrapper

包简介

Custom curl http request wrapper

README 文档

README

This is a simple library to wrap & manage native PHP HTTP requests (there are plenty of serious alternatives like Guzzle, this is my tiny approach to be used in some of my personal projects, should not be taken too seriously).

Requirements

  • mininum php version 8.4
  • curl extension must be enabled

Limitations

At this time only GET/HEAD methods are supported.

Install (composer) dependencies:

composer require aportela/httprequest-wrapper

Code example:

<?php

    require "vendor/autoload.php";

    $logger = new \Psr\Log\NullLogger("");

    // it requires curl extension, otherwise an \aportela\HTTPRequestWrapper\Exception\CurlMissingException is thrown
    $http = new \aportela\HTTPRequestWrapper\HTTPRequest($logger, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1");

    try {
        $response = $http->GET("https://packagist.org/packages/aportela/httprequest-wrapper");
        if ($response->code == 200) {
            echo $response->body . PHP_EOL;
        } else {
            echo "Error getting remote url, http response code: {$response->code}" . PHP_EOL;
        }
    } catch (\aportela\HTTPRequestWrapper\Exception\CurlExecException $e) {
        // this exception is thrown if the curl execution fails and the remote server does not respond (ex: cannot open the connection, the connection has been reset, ...)
        echo "Error executing curl: " . $e->getMessage();
    }

Response object struct:

code: HTTP response code (int)
contentType: response content type (string)
headers: response headers (array)
body: response body contents (null|string)

PHP Composer

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: AGPL-3.0-only
  • 更新时间: 2022-04-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固