我正在尝试将帖子请求发送到包含帖子数据和文件上传的php文件,这里是我发送的内容,设置 Headers 的代码,我拥有的php文件以及我得到的内容从php文件返回:( [图像文件内容]是我发送的图像文件的二进制数据的占位符)
我的问题是$ _POST和$ _FILES都没有显示空数组 . 我想弄清楚如何解决这个问题 .
//我发送给服务器的数据:
--boundary
content-disposition: post; name='param1'
value1
--boundary
content-disposition: post; name='field2'
value2
--boundary
content-disposition: post; name='field3'
value3
--boundary
content-disposition: form-data; name='file'; filename='app/native/assets/sampleFile.jpg'
Content-Type: image/jpg
Content-Transfer-Encoding: binary
[image file content]
--boundary--
-----------------------------------------------------
对于我的 Headers ,我有:
request.setRawHeader("Content-Type", "mulipart/form-data, boundary=boundary");
//data holds the string above
request.setRawHeader("Content-Length", QString::number(data.length()).toAscii());
php文件:
<?php
echo "\npost:\n\n";
print_r($_POST);
echo "\nfiles:\n\n";
print_r($_FILES);
?>
来自php文件的结果:
post:
Array
(
)
files:
Array
(
)
1 回答
尝试类似的东西