使用7.2.0.GA SDK的Titanium POST表单参数无法在Android上运行

问题描述 投票:0回答:1

由于某些奇怪的原因,以下代码不再适用于Android。在iOS上这个代码仍然可以工作,但由于某些原因在Android设备上看起来它不再将参数作为表单参数发送到服务器。在Titanium的早期版本(6.0.2.GA)中,它工作正常。现在我使用的是7.2.0.GA SDK。是否有人知道在升级后可能导致此代码不再起作用的原因是什么?

var loginModel = {
    username: 'blabla',
    password: 'password'
};
xhr.open("POST", 'http://someurl');
xhr.send(loginModel);
titanium appcelerator titanium-alloy titanium-android
1个回答
0
投票

我必须测试的最低SDK是7.3.1.GA和这段代码:

var loginModel = {
    username: 'blabla',
    password: 'password'
};

var xhr = Ti.Network.createHTTPClient({
    onload: function(e) {
        Ti.API.info("Received text: " + this.responseText);
    },
    onerror: function(e) {
        Ti.API.debug(e.error);
    },
    timeout: 5000
});
xhr.open("POST", 'https://httpbin.org/post');
xhr.send(loginModel);

结果如下:

[INFO]  "args": {},
[INFO]  "data": "",
[INFO]  "files": {},
[INFO]  "form": {
[INFO]  "password": "password",
[INFO]  "username": "blabla"
[INFO]  },
[INFO]  "headers": {
[INFO]  "Accept-Encoding": "identity",
[INFO]  "Content-Length": "33",
[INFO]  "Content-Type": "application/x-www-form-urlencoded",
[INFO]  "Host": "httpbin.org",
[INFO]  "User-Agent": "Appcelerator Titanium/7.3.1 ()",
[INFO]  "X-Requested-With": "XMLHttpRequest",
[INFO]  "X-Titanium-Id": ""
[INFO]  },
[INFO]  "json": null,
[INFO]  "origin": "",
[INFO]  "url": "https://httpbin.org/post"
[INFO]  }

所以发送正确的结果。您可以使用SDK尝试此代码或尝试更新(7.2.0从2018年6月开始)

© www.soinside.com 2019 - 2024. All rights reserved.