Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-13555

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

    Details

      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.

        Attachments

          Activity

            People

            • Assignee:
              cbarber Chris Barber
              Reporter:
              dcassenti Davide Cassenti
              Reviewer:
              Chris Barber
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-16244
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration