添加POST文件。
function swoole_http_client->addFile(string $path, string $name, string $filename = null,
string $mimeType = null, int $offset = 0, int $length = 0)
basename($path)
使用addFile
会自动将POST的Content-Type
将变更为form-data
。addFile
底层基于sendfile
,可支持异步发送超大文件。
addFile在1.8.9或更高版本可用
$offset, $length 参数在1.9.11或更高版本可用
<?php
$cli = new swoole_http_client('127.0.0.1', 80);
//post request
$cli->setHeaders(['User-Agent' => "swoole"]);
$cli->addFile(__DIR__.'/post.data', 'post');
$cli->addFile(dirname(__DIR__).'/test.jpg', 'debug');
$cli->post('/dump2.php', array("xxx" => 'abc', 'x2' => 'rango'), function ($cli) {
echo $cli->body;
});