Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13555] MobileWeb: Cannot change Content-Type passing an object in the send() method of Ti.Network.HTTPClient

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-08-30T18:50:53.000+0000
Affected Version/sn/a
Fix Version/s2013 Sprint 18, 2013 Sprint 18 Tooling, Release 3.1.3, Release 3.2.0
ComponentsMobileWeb
Labelsn/a
ReporterDavide Cassenti
AssigneeChris Barber
Created2013-04-15T11:59:36.000+0000
Updated2017-03-14T21:13:48.000+0000

Description

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.

Comments

  1. Bert Grantges 2013-08-06

    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.
  2. Bryan Hughes 2013-08-06

    PR: https://github.com/appcelerator/titanium_mobile/pull/4546
  3. Bert Grantges 2013-08-06

    Hey Bryan - Note that i'm seeing this with iOS as well - should i open a seperate ticket for it?
  4. Bryan Hughes 2013-08-06

    Hi Bert, Yes, please do open a new ticket.
  5. Bryan Hughes 2013-08-16

    3_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/4578
  6. Bryan Hughes 2013-08-16

    Re-opening for the 3.1.3 backport PR
  7. Eric Merriman 2013-08-23

    Worked with Bryan, and with the sample code above, not seeing any content-type in the request header.
  8. Ingo Muschenetz 2013-08-30

    [~bhughes] Is this supposed to be resolved?
  9. Lee Morris 2017-03-14

    Closing ticket as the issue will not fix.

JSON Source