swoole_http2_client->post

发起POST请求,函数原型:

function swoole_http2_client->post(string $path, mixed $data, callable $callback);
  • $path 设置URL路径,如/index.html,注意这里不能传入http://domain
  • $data 请求的包体数据,如果$data为数组底层自动会打包为x-www-form-urlencoded格式的POST内容,并设置Content-Typeapplication/x-www-form-urlencoded
  • $callback 调用成功或失败后回调此函数

使用实例

$cli = new swoole_http2_client('127.0.0.1', 80); 
$cli->post('/post.php', array("a" => '1234', 'b' => '456'), function ($response) {
    echo "Length: " . strlen($cli->body) . "\n";
    echo $cli->body;
});