在修改请求时使用http发送邮件(firefox扩展)

在修改请求时使用http发送邮件(firefox扩展),firefox,firefox-addon,firefox-addon-sdk,Firefox,Firefox Addon,Firefox Addon Sdk,我需要将POST数据记录和更改作为FF扩展来实现。我已经设法产生了一些工作代码,但它工作错误,看起来像是在任何请求方法上触发,而不仅仅是在需要时发布。似乎所有步骤都是根据mozilla教程完成的,但由于某些原因,它并没有按预期工作。这是片段 observe: function(subject, topic, data) { if (topic == "http-on-modify-request") { var httpChannel = sub

我需要将POST数据记录和更改作为FF扩展来实现。我已经设法产生了一些工作代码,但它工作错误,看起来像是在任何请求方法上触发,而不仅仅是在需要时发布。似乎所有步骤都是根据mozilla教程完成的,但由于某些原因,它并没有按预期工作。这是片段

observe: function(subject, topic, data) 
      {
        if (topic == "http-on-modify-request") {
          var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
          //httpChannel.setRequestHeader("X-Hello", "World", false);
          //console.log("http-on");
          if(httpChannel.requestMethod == "POST")
            {
                console.log("in");
                var uploadChannel = httpChannel.QueryInterface(Ci.nsIUploadChannel);
                var uploadStream = uploadChannel.uploadStream;
                uploadStream.QueryInterface(Ci.nsISeekableStream).
                             seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
                var binStream = Cc["@mozilla.org/binaryinputstream;1"].
                                createInstance(Ci.nsIBinaryInputStream);
                binStream.setInputStream(uploadStream);
                var postBytes = binStream.readByteArray(binStream.available());
                var postString = String.fromCharCode.apply(null, postBytes);
                console.log("read");
                console.log(postString);
            }

        }
      },      
谢谢你抽出时间

UPD:

有一个想法是这样做来过滤POST请求

var postBytes = binStream.readByteArray(binStream.available());
uploadStream.QueryInterface(Ci.nsISeekableStream).
             seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);

var postString = String.fromCharCode.apply(null, postBytes);
var tmp = postString.split("\r\n\r\n");

if(tmp[1] && tmp[1].length <= 1024 )
{               
    //log & process
}
var postBytes=binStream.readByteArray(binStream.available());
uploadStream.QueryInterface(Ci.nsiseakblestream)。
寻道(Ci.nsisekablestream.NS_seek_SET,0);
var postString=String.fromCharCode.apply(null,postBytes);
var tmp=postString.split(“\r\n\r\n”);

如果(tmp[1]&&tmp[1].length,因此
httpChannel.requestMethod==“POST”
不足以将其归档?顺便说一句,我看到有人将POST数据读取为string-@Noitidart,嘿,感谢链接,我将为自己制作一个非文本。是的,看起来这样的条件还不够。我在表单提交之前访问了一个站点,控制台上满是文本“in”消息和页面源。