salamek/http-request
最新稳定版本:v1.1
Composer 安装命令:
composer require salamek/http-request
包简介
Simple class to perform requests to web apps
关键字:
README 文档
README
Simple class to perform requests to web apps acting as browser, storing cookies between redirects and so
Install
composer require salamek/http-request dev-master
Usage
<?php include('vendor/autoload.php'); $httpRequest = new Salamek\HttpRequest('cookie-jar.txt'); $httpResponse = $httpRequest->post('http://example.com/sign/in', ['username' => 'my-username', 'password' => 'my-password']); echo '<pre>'; print_r($httpResponse); print_r($httpResponse->getBody(Salamek\HttpResponse::FORMAT_HTML)); //Xpath echo '</pre>';
Doc
/** * HttpRequest constructor. * @param $cookieJar string to store cookies * @param int $maxRedirections redirections allowed (to prevent infinite redirection loop) */ public function __construct($cookieJar, $maxRedirections = 10); /** * Sets maxRedirections * @param int $maxRedirections max redirections allowed (to prevent infinite redirection loop) */ public function setMaxRedirections($maxRedirections); /** * Sends GET Request * @param string $url url to load * @param array $parameters get parameters as array * @return HttpResponse */ public function get($url, array $parameters = []); /** * Sends POST Request * @param string $url to send post request * @param array $parameters post parameters * @return HttpResponse */ public function post($url, array $parameters = []); /** * Sends PUT Request * @param string $url to send put request * @param array $parameters put parameters * @return HttpResponse */ public function put($url, array $parameters = []); /** * Sends DELETE Request * @param string $url to send DELETE request * @param array $parameters DELETE parameters * @return HttpResponse */ public function delete($url, array $parameters = []); /** * Absolutizes url * @param string $baseUrl base url, usualy url of loaded page * @param string $url url to absolutize, usualy url from loaded page * @return string absolutized url */ public static function absolutizeHtmlUrl($baseUrl, $url); /** * Creates file string for file upload * @param string $path path to file * @param string $mime mime type of file * @param string $name send name of file * @return \CURLFile */ public static function createFile($path, $mime, $name);
/** * HttpResponse constructor. * @param $body * @param array $info * @param $lastUrl * @param array $headers */ public function __construct($body, array $info, $lastUrl, array $headers); /** * Returns headers * @return array */ public function getHeaders(); /** * Returns body, formated by $format FORMAT_RAW, FORMAT_JSON, FORMAT_HTML * @param string $format * @return \DOMXPath|mixed */ public function getBody($format = self::FORMAT_RAW); /** * Returns rawBody FORMAT_RAW * @return mixed */ public function getRawBody(); /** * Returns info * @return array */ public function getInfo(); /** * Returns last loded URL * @return mixed */ public function getLastUrl();
salamek/http-request 适用场景与选型建议
salamek/http-request 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.7k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 salamek/http-request 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 salamek/http-request 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 salamek/http-request 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
http客户端
Easily add Excepct-CT header to your project
Build mini web servers in PHP for testing
Cbox SSRF — a hardened, config-driven guard against server-side request forgery for outbound URLs in Laravel. Blocks private/reserved/cloud-metadata targets, pins DNS, and refuses redirects.
Eventually this library may have some useful HTTP-related helpers, but currently there's only HTTP response status codes.
统计信息
- 总下载量: 13.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2016-05-13