1

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);
Rene Pot
  • 24,681
  • 7
  • 68
  • 92
Tranquilized
  • 721
  • 2
  • 6
  • 23

1 Answers1

0

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)

miga
  • 3,997
  • 13
  • 45
  • If I test it through httpbin.org I get the same results indeed but for some reason if I point it to a real environment the form parameters and/or body is not available. I use an NGINX proxy in front of a Tomcat application server. If I send the request directly to the tomcat server it works but through the proxy it doesn't. I upgraded to 7.5.3 titanium SDK and still the same result. I really don't understand why it doesn't work anymore. – Tranquilized May 01 '19 at 13:49