我尝试使用HttpRequest类尝试HTTP POST并从本地php脚本发送文件。 testupload.php的代码是:
<?php
$r = new HttpRequest('http://127.0.0.1:5090/upload.php', HttpRequest::METH_POST);
$r->addPostFile('app', 'abc.txt');//if this line is commented the exception is gone
try {
echo $r->send()->getBody();
} catch (HttpException $ex) {
echo $ex;
}
?>
我在以下情况下遇到以下异常:
exception 'HttpInvalidParamException' with message 'Empty or too short HTTP message: ''' in
D:\xampp\htdocs\testupload.php:0 inner exception 'HttpRequestException' with
message 'Failed to open/read local data from file/application; failed creating formpost
data (http://127.0.0.1:5090/upload.php)' in D:\xampp\htdocs\testupload.php:8
Stack trace: #0 D:\xampp\htdocs\testupload.php(0): HttpRequest->send() #1 {main}
文件abc.txt位于同一目录中。有什么问题?
答案 0 :(得分:0)
也许有点迟了但是在调用“$ r-&gt; send() - &gt; getBody();”之前,请尝试检查是否有意外删除(取消链接)文件。 (这是我的经历)。如果您不删除该文件,请尝试添加该文件的绝对路径和/或检查文件访问权限。