多部分/表单数据在ionic iOS上不起作用



我有一个ionic 3项目,它允许将文件上传到服务器。以下代码在Android上运行良好。但在iOS上,它似乎被阻止了(即/upload.php上的服务器代码在这两种情况下显然是相同的,但来自iOS的它没有收到任何发布的数据(。

this.http.setDataSerializer('urlencoded');
this.http.post("http://example.com/upload.php", {
name: this.filename,
data: this.datafile
}, {"Content-Type":"multipart/form-data"})
.then(res => {
console.log('success response: ' + res.data); 
}, error => {
console.log(error: ' + error);
});

有什么想法吗?

xCode中是否有一些设置需要配置为允许多部分/表单数据发布工作?或者可能在某个地方将域列入白名单以允许它?

原来是在服务器端。显然,PHP接收帖子的方式与Android和iOS不同$_REQUEST["xxxx"]适用于Android,但为了同时适用于两者,它需要以下内容:

$postdata = file_get_contents("php://input");
parse_str($postdata, $param);
// then available as $param["xxxx"]

我想我会在这里更新答案,以防其他人碰到这个问题。太晦涩了,我花了好几天才弄明白!

最新更新