Titanium Community Questions & Answer Archive

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

Can't use getResponseHeader()

I want to use Titanium.Network.createHTTPClient() to download a media file from a web server and save it locally. The URL's being used do not provide any clue as to what type file is being transfered. The filename and type is included in the response header. When I try to access the headers using getResponseHeader('Content-Type');, I get NULL. No matter what value I send to getResponseHeader I get NULL. I am attempting to do all this in onload. I've tried the following:

xhr.onload = function(e) {

Ti.API.info("Onload:"+e); //Does nothing, Ti.API.info broken.
alert(e.getResponseHeader('Content-Type'); // NULL
alert(xhr.getResponseHeader('Content-Type'); // NULL
alert(this.getResponseHeader('Content-Type'); // NULL
}

How do I gain access to the response headers?

— asked August 15th 2010 by Ben Hornedo
  • getresponseheaders
  • headers
  • http
  • xhr
0 Comments

2 Answers

  • Doesn't .getResponseHeader belong to HTTPClient?

    In that case, wouldn't you call it using the following:

    loader.getResponseHeader('Content-Type');
    

    instead of putting it inside your .onload function?

    — answered September 30th 2010 by Ted W
    permalink
    1 Comment
    • This is true

      — commented September 30th 2010 by Richard Venneman
  • Hey Ben. 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
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.