grantholle / pear-http-request2
pear/http_request2的端口:提供一种简单执行HTTP请求的方法。
4.0.0
2023-02-15 09:51 UTC
Requires
- php: ^8.1
- ext-curl: *
- ext-fileinfo: *
- ext-mbstring: *
- ext-zlib: *
- grantholle/pear-net-url2: ^4.0
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^8
Suggests
- ext-openssl: Allows handling SSL requests when not using cURL.
README
提供一种简单执行HTTP请求的方法,使用可插拔的适配器
- Socket:HTTP协议的纯PHP实现(不使用http流包装器),基于较旧的PEAR HTTP_Request包
- Curl:PHP的cURL扩展的包装器
- Mock:用于测试依赖HTTP_Request2的包,返回预定义的响应而不进行网络交互
Socket和Curl适配器都支持带有数据和文件上传的POST请求,基本和摘要认证,cookies,跨请求管理cookies,HTTP和SOCKS5代理,gzip和deflate编码,重定向,使用观察者监控请求进度...
此包是PEAR HTTP_Request2,并已从PEAR SVN迁移过来
请通过GitHub问题报告所有问题。
欢迎提交拉取请求。
基本用法
require_once 'src/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