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?
2 Answers
-
Doesn't
.getResponseHeader
belong toHTTPClient
?In that case, wouldn't you call it using the following:
loader.getResponseHeader('Content-Type');
instead of putting it inside your
.onload
function? -
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.