HTTPClient will not send a POST HTTP request
All requests coming to the server from HTTPClient are GET requests, no matter what I set it to.
Here is the code:
var request = Titanium.Network.createHTTPClient(),
request.open("POST", "http://test.com");
request.onload = function() {
try {
var content = JSON.parse(this.responseText);
if(content.error == undefined) {
// do some things
} else {
alert(content.error);
}
} catch (err) {
Titanium.API.error(err);
Titanium.UI.createAlertDialog({
message : err,
title : "Remote Server Error"
});
}
};
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send({ test: 'test'});
I've also tried not setting the header and also passing in the data as a string instead of an object. No matter what the server says it is a GET request. Any help would be great. Thanks.
1 Answer
-
The order that the methods are set also is important.
Please find below the KitchenSink example that shows when the open is issued.
https://github.com/appcelerator/titanium_mobile/blob/master/demos/KitchenSink/Resources/examples/xhr_fileupload.jsYou might also want to add the onerror handler, it is useful in dealing with xhr errors