Swoole\Coroutine\Http\Client->post

Declaration

<?php
Swoole\Coroutine\Http\Client->post(string $path, mixed $data)

Parameters

path

The path.

data

The data to be sent for the HTTP reqeust.

Return

Description

Send the HTTP POST reqeust to the remote server.

Example

<?php
use Swoole\Coroutine\HTTP\Client;

Co\run(function() {
    $cli = new Client('127.0.0.1', 80);
    $cli->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);
    $cli->set([ 'timeout' => 1]);
    $cli->post('/index.php', ['a'=> 123,'b'=>"hey"]);
    echo $cli->body;
    $cli->close();
});