Titanium POST form parameters not working on Android with 7.2.0.GA SDK

170 Views Asked by At

For some strange reason the following code doesn't work properly on Android anymore. On iOS this code still works but for some reason on an Android device it looks like it doesn't send the parameters as form parameters to the server anymore. In previous versions (6.0.2.GA) of Titanium it worked properly. Now I am using the 7.2.0.GA SDK. Does anybody know what could cause this code not to work anymore after the upgrade?

var loginModel = {
    username: 'blabla',
    password: 'password'
};
xhr.open("POST", 'http://someurl');
xhr.send(loginModel);
1

There are 1 best solutions below

1
miga On

The lowest SDK I had to test is 7.3.1.GA and this code:

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);

with this result:

[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]  }

So is sending the correct result. You could try this code with your SDK or try to update (7.2.0 is from June 2018)