webguosai/http-client
Composer 安装命令:
composer require webguosai/http-client
包简介
http客户端
关键字:
README 文档
README
运行环境
- php >= 5.6
- composer
安装
composer require webguosai/http-client -vvv
使用
初始化
$options = [ //超时(单位秒) 'timeout' => 3, //代理ip池(允许填写多个,会随机使用一组) 'useSocks5' => true, // 使用 socks5 代理 'proxyIps' => [ //格式为【ip:端口】 '0.0.0.0:8888' ], //重定向、及最多重定向跳转次数 'redirects' => false, 'maxRedirect' => 5, //cookie自动保存路径 'cookieJarFile' => 'cookie.txt', //ca证书路径 'caFile' => __DIR__.'/cacert/cacert.pem', ]; $http = new \Webguosai\HttpClient($options);
请求
$headers = [ 'User-Agent' => 'http-client browser', 'cookie' => 'login=true' ]; $data = ['data' => '111', 'data2' => '222']; //所有方法 $response = $http->get($url, $data, $headers); $response = $http->post($url, $data, $headers); $response = $http->put($url, $data, $headers); $response = $http->patch($url, $data, $headers); $response = $http->delete($url, $data, $headers); $response = $http->head($url, $data, $headers); $response = $http->options($url, $data, $headers);
响应
$response->request; //请求 $response->headers; //响应头 $response->body; //响应body $response->httpStatus; //http状态码 $response->contentType; //内容类型 $response->info; //其它信息 $response->info['url'];//最终请求的地址 $response->getHtml(); //获取html $response->getChatset(); //编码 $response->json(); //json $response->xml(); //xml $response->ok();//http=200返回真 $response->getErrorMsg(); //错误信息
data 传值方式
// multipart/form-data $data = ['data' => '111', 'data2' => '222']; // application/x-www-form-urlencoded $data = http_build_query($data); // application/json $data = json_encode($data); // 文件上传 $_FILES['file'] 接收 $data = [ 'file' => new \CURLFile('1.jpg'), ]; $response = $http->post($url, $data);
headers 传值方式
//数组传递 $headers = [ 'User-Agent: chrome', 'User-Agent' => 'chrome', ]; //纯字符串 (一般为从浏览器复制) $headers = 'User-Agent: chrome Referer: https://www.x.com Cookie: cookie=6666666'; $response = $http->post($url, $data, $headers);
实操
$options = [ 'timeout' => 3, ]; $http = new \Webguosai\HttpClient($options); $response = $http->get('http://www.baidu.com'); if ($response->ok()) { var_dump($response->body); //var_dump($response->json()); } else { var_dump($response->getErrorMsg()); }
打赏
License
MIT
webguosai/http-client 适用场景与选型建议
webguosai/http-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 486 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「httpclient」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webguosai/http-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webguosai/http-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webguosai/http-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A throttler for symfony/http-client to handle rate limits
Send SMS messages through the LabsMobile platform and the PHP library.
curl oop
Easily add Excepct-CT header to your project
A simple lightweight HTTP client for php
统计信息
- 总下载量: 486
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-15