我正在编写API客户端,但是无法通过pecl_http发送文件。我将所有内容都写在http \ Client上。大多数事情都是通过复制邮递员的东西,但是当我发送时,我得到的是空文件。我应该如何发送?我该如何在脚本中将$ _FILES变量与数据一起放入?
output = [input[i][0] + input[i][2] for i in range(2, len(input), 2) if i.endswith(".xml"]
答案 0 :(得分:0)
<?php
$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HTTP_METH_POST);
// if redirects is set to true, a single redirect is allowed;
// one can set any reasonable count of allowed redirects
$r->setOptions(
array( 'cookies' => array('MyCookie' => 'has a value'),
'redirect' => true,
)
);
// common form data
$r->setPostFields(
array( 'name' => 'Mike',
'mail' => 'mike@php.net',
)
);
// add the file to post (form name, file name, file type)
touch('profile.jpg');
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
print $r->send()->getBody();
} catch (HttpException $e) {
print $e;
}
?>