Issue Description
When a Titanium HTTPClient request is opened and sent, the header "X-Requested-With: XMLHttpRequest" is sent with the request by default. This usually is not a problem, however, this header currently results in an error message being returned from the particular API that I'm using (shopify API).
I've set this header to null in my controller code, which fixes the problem in Android, but not in iOS as the X-Requested-With header is still being set in iOS.
Test Case
var url = 'https://shopname.myshopify.com/admin/products.json';
var client = Ti.Network.createHTTPClient({
timeout : 5000,
withCredentials : true,
validatesSecureCertificate : true
});
client.onload = function(e) {
Ti.API.info("Received text!" + this.responseText);
};
client.onerror = function(e) {
Ti.API.debug("error");
Ti.API.debug(e);
};
client.onreadystatechange = function(e) {
Ti.API.info("state changed");
Ti.API.info(this.readyState);
Ti.API.info(client.getAllResponseHeaders());
Ti.API.info("************");
};
client.setUsername("user");
client.setPassword("pass");
client.open("GET", url);
client.setRequestHeader('X-Requested-With', null);
client.send();
Request Raw Response
{quote}
GET /admin/products.json HTTP/1.1
Host: shopname.myshopify.com
X-Titanium-Id: f2e11973-5eac-4106-b95d-6690ddd8683e
X-Requested-With: XMLHttpRequest
Proxy-Connection: keep-alive
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-us
Connection: keep-alive
User-Agent: Appcelerator Titanium/3.4.1 (iPhone Simulator/8.1; iPhone OS; en_US;)
{quote}
Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/6645
Verified fix using: Mac OSX 10.10.2 Titanium SDK build: 4.0.0.v20150323131014 Titanium CLI, build: 4.0.0-alpha Alloy: 1.6.0-alpha Xcode 6.2 iPhone 6 (8.2) If the second argument is set to null then the headers are not sent. Closing ticket.