Environment
- OS: Mac OS X Yosemite, 10.10.1
- Mobile Platform(s): Genymotion Android 4.3 - API 18, iOS 8 - iPhone 5, 5s, 6 emulator
- Titanium SDK: 3.4.1.GA
- Titanium Studio: 3.4.1.201410281727
Problem
This is a follow up from this Q&A post. The gist of the problem is this: When a Titanium HTTPClient request is opened and sent, the header X-Requested-With: XMLHttpRequest is sent with the request by default. However, this header 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. Is there something I'm missing?
My HTTPClient is set up as follows:
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();As previously mentioned, this implementation works perfectly in Android. However, in looking at the raw request headers captured from the iOS simulator (using Charles), the
X-Requested-With: XMLHttpRequest is still being set, which results in the error seen in the aforementioned Q&A post.