我可以在Firefox扩展中获取当前页面的URL,但我也想获取POST数据。Firefox将其存储在某个位置,以便在刷新时再次发送。我怎样才能从我的分机上得到它?
我可能会像Firebug一样捕获每个请求,但我宁愿避免这样做,只按需获取POST数据。
我在用add-on SDK (jetpack)。我在我的主脚本中尝试了this page中的代码:
{Cc,Ci} = require("chrome");
wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
mainWindow = wm.getMostRecentWindow("navigator:browser");
history = mainWindow.gBrowser.selectedBrowser.webNavigation.sessionHistory;
postdata = history.getEntryAtIndex(history.index-1,false).QueryInterface(Ci.nsISHEntry).postData;
postdata.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
stream.setInputStream(postdata);
postBytes = stream.readByteArray(stream.available());
poststr = String.fromCharCode.apply(null, postBytes);
console.log(poststr);但它在以下方面失败
postdata.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);因为postdata is null (TypeError)。
我还在附加到活动选项卡的内容脚本中尝试了此方法,但它失败了,并在获取Components.classes时出现权限被拒绝。
发布于 2011-07-12 04:07:18
这段代码检索最后一个页面的POST数据,而不是当前页面。
我将history.index-1更改为history.index,它可以正常工作。
https://stackoverflow.com/questions/6634289
复制相似问题