javascript - Get Response Header/Body -
i'm developing firefox addon , i'm listening http responses this:
var observerservice = components.classes["@mozilla.org/observer-service;1"].getservice(components.interfaces.nsiobserverservice); observerservice.addobserver(httpobserver, "http-on-examine-response", false);
which calls httpobserver object looks this:
var httpobserver = { observe : function(asubject, atopic, adata) { asubject.queryinterface(components.interfaces.nsihttpchannel); httpstatus = asubject.responsestatus; if(httpstatus == 200 && asubject.contenttype.tostring().indexof("text/") != -1) { alert("url: " + asubject.name + "\r\nstatus: " + httpstatus + "\r\ncontenttype: " + asubject.contenttype); //works great alert("body: " + asubject.responsetext); //is undefined, why? } else if(httpstatus == 404 && asubject.contenttype.tostring().indexof("text/html") != -1) alert("page not found!\r\nurl: " + asubject.name + "\r\ncontenttype: " + asubject.contenttype); } };
i've got following problem(s):
i'd whole body , header response don't know how. once read problem server not in same domain, how firefox handles then?
i did lot of research didn't find usefull, maybe missed something..
btw.: i've got access request object if helps.
you use nsitraceablechannel
interface that, implemented http requests. allows replace channel listener 1 of own, can read out data in ondataavailable
call before passing on original listener. there example code doing here: http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
Comments
Post a Comment