首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Firefox扩展中检索当前网页的帖子数据

问在Firefox扩展中检索当前网页的帖子数据
EN

Stack Overflow用户
提问于 2011-07-09 18:52:35
回答 1查看 1.3K关注 0票数 2

我可以在Firefox扩展中获取当前页面的URL,但我也想获取POST数据。Firefox将其存储在某个位置,以便在刷新时再次发送。我怎样才能从我的分机上得到它?

我可能会像Firebug一样捕获每个请求,但我宁愿避免这样做,只按需获取POST数据。

我在用add-on SDK (jetpack)。我在我的主脚本中尝试了this page中的代码:

代码语言:javascript
复制
{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);

但它在以下方面失败

代码语言:javascript
复制
postdata.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);

因为postdata is null (TypeError)。

我还在附加到活动选项卡的内容脚本中尝试了此方法,但它失败了,并在获取Components.classes时出现权限被拒绝。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-12 04:07:18

这段代码检索最后一个页面的POST数据,而不是当前页面。

我将history.index-1更改为history.index,它可以正常工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6634289

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档