Problem description
When trying to change the Content-Type of the HTTPClient request (e.g. to set it to application/json), the header sent still contains the default application/json,application/x-www-form-urlencoded value, in addition to what was set.
Steps to reproduce
Use the following code:
var win = Ti.UI.createWindow();
win.open();
var xhr = Ti.Network.createHTTPClient({
onload : function(e) {
Ti.API.info('onload called, readyState = ' + this.readyState);
},
onerror : function(e) {
Ti.API.info('onerror called, readyState = ' + this.readyState);
},
timeout : 30000 /* in milliseconds */
});
xhr.open("POST", 'http://127.0.0.1:8020/');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send({
"CountryCode" : "ITA"
});
When running the code in MobileWeb, the Content-Type header will contain:
Content-Type: application/json, application/x-www-form-urlencoded
Additional notes
According to the XMLHttpRequest specifications, setRequestHeader will add the request header when called, and not replace it. Apparently, "application/x-www-form-urlencoded" is always set if any data is sent.
I'm able to reproduce this on iOS using Ti SDK 3.1.1.GA. Android works just fine. We're seeing this as an issue for a prospect as well.
PR: https://github.com/appcelerator/titanium_mobile/pull/4546
Hey Bryan - Note that i'm seeing this with iOS as well - should i open a seperate ticket for it?
Hi Bert, Yes, please do open a new ticket.
3_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/4578
Re-opening for the 3.1.3 backport PR
Worked with Bryan, and with the sample code above, not seeing any content-type in the request header.
[~bhughes] Is this supposed to be resolved?
Closing ticket as the issue will not fix.