- Coroutine\Http2\Client
- 实例
- 实例
Coroutine\Http2\Client
Http2
协程客户端。
实例
go(function () {
$domain = 'www.zhihu.com';
$cli = new Swoole\Coroutine\Http2\Client($domain, 443, true);
$cli->set([
'timeout' => -1,
'ssl_host_name' => $domain
]);
$cli->connect();
$req = new swoole_http2_request;
$req->method = 'POST';
$req->path = '/api/v4/answers/300000000/voters';
$req->headers = [
'host' => $domain,
"user-agent" => 'Chrome/49.0.2587.3',
'accept' => 'text/html,application/xhtml+xml,application/xml',
'accept-encoding' => 'gzip'
];
$req->data = '{"type":"up"}';
$cli->send($req);
$response = $cli->recv();
assert(json_decode($response->data)->error->code === 602);
});