Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

HTTPClient: broken and missing functionality

The documentation for HTTPClient says: "This object (mostly) implements the XMLHttpRequest specification". However, compared to the standard XMLHttpRequest implementations it has two big problems:

A. getResponseHeader() doesn't work:

A lot of people got burned by this problem and there seems to be a bug filed for the issue, but it keeps getting pushed back with every new release. For most internet or cloud oriented mobile applications this is a major problem because important application information is often transfered in response headers (e.g., Amazon S3 storage or Window Azure Blob storage uses response headers to return property and metadata information).

B. getAllResponseHeaders() is not implemented at all:

This is a huge problem for internet and cloud oriented mobile applications too. In some cases it's a complete show stopper. Take Windows Azure Blob storage. Their API returns metadata in response header that you don't even know what it might be. All you know is that the metadata headers start with a known prefix. To get those metadata headers you need to be able to look at all available headers, but HTTPClient doesn't support it.

Question:

  1. Will issue A be fixed any time soon?
  2. Are there any plans to implement getAllResponseHeader()?
— asked August 29th 2010 by Kyle Quest
  • getallresponseheaders
  • getresponseheader
  • httpclient
0 Comments

5 Answers

  • This is a big problem for us right now.. any news?

    — answered September 29th 2010 by dan bachelder
    permalink
    0 Comments
  • Hey Guys. I had the same problem. There is a work around for the getReponseHeader() problem here: https://appcelerator.lighthouseapp.com/projects/32238/tickets/1502-httpclient-problems-with-header-parsing-and-responsedata-in-onerror-handler

    See the part by Brion on using a reference to the original object instead of 'this'. Works for me in 1.4.1.1 on OS4 on the iPad.

    — answered October 24th 2010 by Jeff Bonnes
    permalink
    0 Comments
  • 6 months later, still no implemetation of getAllResponseHeaders()…

    I believe this is a very useful function, will it be implemented one day?

    — answered February 2nd 2011 by Thomas Dall'Agnese
    permalink
    1 Comment
    • it fixed

      — commented February 2nd 2011 by Aaron Saunders
  • I think it works under getResponseHeaders()

    var xhr = Titanium.Network.createHTTPClient();
    xhr.onerror = function(e) {
    };
    xhr.onload = function() {
        Ti.API.info("ERROR " + JSON.stringify(xhr.getResponseHeaders()));
    };
    xhr.open('GET', 'http://nodejs.org/');
    xhr.send({});
    

    output

    [INFO] ERROR {
    "Accept-Ranges":"bytes",
    "Server":"nginx",
    "Connection":"keep-alive",
    "Last-Modified":"Fri, 28 Jan 2011 05:14:52 GMT",
    "Content-Type":"text/html",
    "Content-Length":"8529","Date":"Wed, 02 Feb 2011 06:11:28 GMT
    "}
    

    getResponseHeader()

    var xhr = Titanium.Network.createHTTPClient();
    xhr.onerror = function(e) {
    };
    xhr.onload = function() {
        Ti.API.info("" + JSON.stringify(xhr.getResponseHeader("Last-Modified")));
    };
    xhr.open('GET', 'http://nodejs.org/');
    xhr.send({});
    

    output

    [INFO] Fri, 28 Jan 2011 05:14:52 GMT
    
    — answered February 2nd 2011 by Aaron Saunders
    permalink
    1 Comment
    • Hi Araon,

      Is there any possibility to use getResponseHeader("Last-Modified") function in the onreadystatechange function? I tried it but I am getting NULL in response!

      What I wanted to achieve is, download resource from server only if it has been modified since last its last download.

      Tech Details: SDK - 3.0.2, Platfrom - iOS

      Thanks in advance.

      — commented March 29th 2013 by Manaday Mavani
  • No it seems to not work under Android (but it's ok under iOS).

    Message: TypeError: Cannot find function getResponseHeaders in object [Ti.Network.HTTPClient]. (file:///android_asset/ (…)

    Please answer.

    — answered March 2nd 2011 by Lucas CHERIFI
    permalink
    1 Comment
    • my suggestion is to create a question specific to your problem and include the OS and the SDK version information.

      I would also look in lighthouse to see if there is any information on this issue.

      — commented March 2nd 2011 by Aaron Saunders
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.