findologic / http_request2
提供了一种简单执行HTTP请求的方法。
v2.4.0
2020-04-15 13:34 UTC
Requires
- php: >=7.3
- pear/net_url2: ^2.2.0
- pear/pear_exception: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^9.0
Suggests
- ext-fileinfo: Adds support for looking up mime-types using finfo.
- ext-zlib: Allows handling gzip compressed responses.
- lib-curl: Allows using cURL as a request backend.
- lib-openssl: Allows handling SSL requests when not using cURL.
This package is auto-updated.
Last update: 2024-09-15 23:19:02 UTC
README
免责声明! 此项目不再积极维护,仅在未来的PHP版本破坏兼容性时才会更新。
如果您有任何原因想使用此项目,请使用 Guzzle 代替。它更好,维护更积极,具有更多功能,如果您想使用PHP发送HTTP请求,通常来说是一个更好的选择。
提供了一种简单执行HTTP请求的方法,使用可插拔的适配器
- Socket:HTTP协议的纯PHP实现(不使用http流包装器),基于较旧的 PEAR HTTP_Request 软件包
- Curl:PHP cURL扩展的包装器
- Mock:用于测试依赖于HTTP_Request2的包,返回预定义的响应,而不进行网络交互
Socket和Curl适配器都支持带有数据和文件上传的POST请求、基本和摘要认证、cookies、跨请求管理cookies、HTTP和SOCKS5代理、gzip和deflate编码、重定向、使用Observers监控请求进度...
此软件包是 PEAR HTTP_Request2,并已从 PEAR SVN 迁移
请通过 PEAR bug tracker 报告所有问题。
欢迎提交pull请求。
基本用法
require_once 'HTTP/Request2.php'; $request = new HTTP_Request2('http://pear.php.net/', HTTP_Request2::METHOD_GET); try { $response = $request->send(); if (200 == $response->getStatus()) { echo $response->getBody(); } else { echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); } } catch (HTTP_Request2_Exception $e) { echo 'Error: ' . $e->getMessage(); }
文档
...可在PEAR网站上找到
当前发布版本的 生成API文档 也可在此处找到。
测试、打包和安装(Pear)
要测试,运行以下之一
$ phpunit tests/
或
$ pear run-tests -r
如果您想执行与Web服务器交互的测试,可能需要设置NetworkConfig.php文件。其模板是NetworkConfig.php.dist文件,请查阅该文件以获取详细信息。
要构建,只需
$ pear package
从头开始安装
$ pear install package.xml
升级
$ pear upgrade -f package.xml