Anyone, help me, how to get Headers and PostData inside extension, using xpcom/something else? i cant find functions inside firebug due t开发者_开发问答o it is big codebase... thank you guys
I am assuming that you want request headers, not response headers. Then you register an observer for the http-on-modify-request
notification. The general documentation is https://developer.mozilla.org/en/Observer_Notifications#HTTP_requests, a code example can be found under https://developer.mozilla.org/en/Creating_Sandboxed_HTTP_Connections#Handling_cookies. Getting the headers is easy, you simply call nsIHttpChannel.getRequestHeader()
.
Getting response headers is similar but you need to listen to http-on-examine-response
notification and probably http-on-examine-cached-response
as well.
POST data is tricky. You can get the upload stream as httpChannel.QueryInterface(Components.interfaces.nsIUploadChannel).uploadStream
. But the stream can only be read once - it is either you or the code sending data to the server. So you need to replace the stream by something that looks identical but allows you to peek on it - probably nsIInputStreamTee where you set the original stream as source and nsIPipe as sink. Not sure whether this is the approach chosen by Firebug.
Wladimir is right on for the headers. For the POST data, here's a couple of code snippets with a little more detail:
https://developer.mozilla.org/en/Code_snippets/Miscellaneous#Getting_postData_of_a_webpage
精彩评论