Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

HTTPClient: setRequestHeader('X-Requested-With', null) ignored in iOS

$
0
0

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.

iOS Raw Request Header
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;)


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>