Reputation: 3
I'm running through this issue since about 2 days and I can't figure out a way to solve it. I have a service that can be called using a specific URL and sending some parameters using method POST and 'application/x-www-form-urlencoded' as data type.
This service will update a database table with a timestamp every time it is called (like 'last time logged in').
On Android my code runs as expected, but running it on iOS (simulator) it does nothing ... Using 'Charles' I know the service is being called from both simulators but I noticed that the response takes about 60ms on iOS and about 10000ms on Android.
This is the code I use to call the service:
function updateUserModules(_params) {
if(_params.Number) {
var token = md5HashEncoder(_params.Number + '$XDTPEP132x ');
Ti.API.warn('TOKEN: ' + token);
var httpClient = Ti.Network.createHTTPClient();
httpClient.open("POST", "https://myxd.xdpartners.com/updateUsedModules");
httpClient.setRequestHeader("content-type", "application/x-www-form-urlencoded");
var params = {
token: token,
licenceNumber: _params.Number,
moduleKeyId: "71",
terminalId: "0",
lastUsedDate: moment().format('YYYY-MM-DD HH:mm:ss')
};
httpClient.send(params);
}
}
Any ideas where the issue is?
Upvotes: 0
Views: 237
Reputation: 440
I believe there is something wrong with you SSL certificate. Running your code with some adjusted params and adding an onerror
handler gives me this output:
[ERROR] : {
[ERROR] : code = "-1202";
[ERROR] : error = "The certificate for this server is invalid. You might be connecting to a server that is pretending to be \U201cmyxd.xdpartners.com\U201d which could put your confidential information at risk.";
[ERROR] : source = "[object TiNetworkHTTPClient]";
[ERROR] : success = 0;
[ERROR] : type = error;
[ERROR] : }
Android >5 is in some cases more forgiving, which might explain why it works there.
Upvotes: 1
Reputation: 1181
Try httpClient.send(JSON.stringify(params));
instead of httpClient.send(params);
This fixed it on my project while I was having the same issues as you.
Upvotes: 0