Coroutine\Http2\Client

Http2协程客户端。

实例

  1. go(function () {
  2. $domain = 'www.zhihu.com';
  3. $cli = new Swoole\Coroutine\Http2\Client($domain, 443, true);
  4. $cli->set([
  5. 'timeout' => -1,
  6. 'ssl_host_name' => $domain
  7. ]);
  8. $cli->connect();
  9. $req = new swoole_http2_request;
  10. $req->method = 'POST';
  11. $req->path = '/api/v4/answers/300000000/voters';
  12. $req->headers = [
  13. 'host' => $domain,
  14. "user-agent" => 'Chrome/49.0.2587.3',
  15. 'accept' => 'text/html,application/xhtml+xml,application/xml',
  16. 'accept-encoding' => 'gzip'
  17. ];
  18. $req->data = '{"type":"up"}';
  19. $cli->send($req);
  20. $response = $cli->recv();
  21. assert(json_decode($response->data)->error->code === 602);
  22. });