Get PostData as in FireBug

孤街浪徒 提交于 2019-12-23 17:53:08

问题


Anyone, help me, how to get Headers and PostData inside extension, using xpcom/something else? i cant find functions inside firebug due to it is big codebase... thank you guys


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6168729/get-postdata-as-in-firebug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!