我正在尝试通过 POST 从 Qt (C++) 应用程序将文件上传到我的网络服务器,运行 LAMP 堆栈。
一切似乎都很顺利,但由于某种原因,脚本$_POST
和$_FILES
数组完全是空的。我尝试使用纯 HTML 表单上传相同的文件,它可以工作。
这是我在 Qt 程序中构造请求的方式:
request.setUrl(ServerAddress);
request.setHeader(request.ContentTypeHeader, "application/x-www-form-urlencoded");
reply = nam.post(request, file);
和 PHP:
<?php
var_dump($_POST);
var_dump($_FILES);
?>
哪里request
是 a QNetworkRequest
,reply
是 a QNetworkReply
,nam
是 QNetworkAccessManager,并且file
是QFile
我的文件的打开位置。
请求发送良好,我什至尝试查看请求是否因使用 Wireshark 搞砸了。这是输出:
POST /upload.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 8
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Accept-Language: en-US,*
User-Agent: Mozilla/5.0
Host: mysite.com
My data!HTTP/1.1 200 OK
Date: Wed, 03 Jul 2013 15:16:37 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.17RC1
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 36
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
array(0) {
}
array(0) {
}
这是一个非常小的文本文件,仅包含“'我的数据!”。我只是不明白为什么 PHP 脚本没有看到该文件。有什么想法我哪里出错了吗?