swlib / saber

⚔️ Saber, PHP异步协程HTTP客户端 | PHP Coroutine HTTP client - Swoole Humanization Library
https://packagist.org/packages/swlib/saber
Apache License 2.0
978 stars 124 forks source link

SaberGM::requests() 的返回结果 #109

Closed ta244100 closed 4 years ago

ta244100 commented 4 years ago

SaberGM::requests() 的返回结果body都是true吗? get又只能单个请求,那么有什么方法批量请求的吗?

sy-records commented 4 years ago

代码贴下。

go(function () {
    $saber = Saber::create(['base_uri' => 'http://httpbin.org']);
    echo $saber->requests(
        [
            ['get', '/get'],
            ['post', '/post'],
            ['patch', '/patch'],
            ['put', '/put'],
            ['delete', '/delete']
        ]
    );
});
ta244100 commented 4 years ago

OK,问题已经找到,requests()的返回结果得先去遍历,才去调用->getParsedJsonArray()处理结果函数,才能看到结果值。