当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 52

huawei / YurunHttp
暂停

forked from 宇润 / YurunHttp 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

YurunHttp

Latest Version IMI Doc IMI License

简介

YurunHttp 是开源的PHP HTTP类库,支持链式操作,简单易用。

支持所有常见的GET、POST、PUT、DELETE、UPDATE等请求方式,支持上传下载、设置和读取header、Cookie、请求参数、失败重试、限速、代理、证书等。

3.0 版完美支持Curl、Swoole 协程。

我们有完善的在线技术文档:http://doc.yurunsoft.com/YurunHttp

API 文档:https://apidoc.gitee.com/yurunsoft/YurunHttp

同时欢迎各位加入技术支持群74401592点击加群,如有问题可以及时解答和修复。

个人精力有限,欢迎各位来提交PR(码云/Github),一起完善YurunHttp,让它能够更加好用。

Composer

本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 composer.json 中加入下面的内容

{
    "require": {
        "yurunsoft/yurun-http": "~3.0"
    }
}

然后执行 composer update 安装。

之后你便可以使用 include "vendor/autoload.php"; 来自动加载类。(ps:不要忘了namespace)

用法

简单调用

<?php
use Yurun\Util\HttpRequest;

$http = new HttpRequest;
$response = $http->ua('YurunHttp')
                 ->get('http://www.baidu.com');

echo 'html:', PHP_EOL, $response->body();

PSR-7 请求构建

<?php
use Yurun\Util\YurunHttp\Http\Request;
use Yurun\Util\YurunHttp;

$url = 'http://www.baidu.com';

// 构造方法定义:__construct($uri = null, array $headers = [], $body = '', $method = RequestMethod::GET, $version = '1.1', array $server = [], array $cookies = [], array $files = [])
$request = new Request($url);

// 发送请求并获取结果
$response = YurunHttp::send($request);

var_dump($response);

Swoole 协程模式

<?php
use Yurun\Util\YurunHttp;
use Yurun\Util\HttpRequest;

// 设置默认请求处理器为 Swoole
YurunHttp::setDefaultHandler('Yurun\Util\YurunHttp\Handler\Swoole'); // php 5.4
// YurunHttp::setDefaultHandler(\Yurun\Util\YurunHttp\Handler\Swoole::class); // php 5.5+

// Swoole 处理器必须在协程中调用
go('test');

function test()
{
	$http = new HttpRequest;
	$response = $http->get('http://www.baidu.com');
	echo 'html:', PHP_EOL, $response->body();
}

具体详见test目录中的示例代码

The MIT License (MIT) Copyright (c) 2017 宇润 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

YurunHttp 是开源的PHP HTTP类库,支持链式操作,简单易用。3.0 版完美支持Curl、Swoole 协程。 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/weizai118/YurunHttp.git
git@gitee.com:weizai118/YurunHttp.git
weizai118
YurunHttp
YurunHttp
master

搜索帮助

14c37bed 8189591 565d56ea 8189591