PHPDaemon\Clients\HTTP\Connection::post PHP Method

post() public method

Perform a POST request
public post ( string $url, array $data = [], array $params = null )
$url string
$data array
$params array
    public function post($url, $data = [], $params = null)
    {
        foreach ($data as $val) {
            if ($val instanceof UploadFile) {
                $params['contentType'] = 'multipart/form-data';
            }
        }
        if (!isset($params['contentType'])) {
            $params['contentType'] = 'application/x-www-form-urlencoded';
        }
        if ($params['contentType'] === 'application/x-www-form-urlencoded') {
            $body = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
        } elseif ($params['contentType'] === 'application/x-json') {
            $body = json_encode($data);
        } else {
            $body = 'Unsupported Content-Type';
        }
        if (!isset($params['headers'])) {
            $params['headers'] = [];
        }
        $params['headers']['Content-Length'] = mb_orig_strlen($body);
        $this->sendRequestHeaders('POST', $url, $params);
        $this->write($body);
        $this->writeln('');
    }