-1

すべての投稿リクエストをキャッチする拡張機能を構築しています。しかし、httpChannel.originalURI.spec には、投稿からの属性はありません。投稿の属性を取得するにはどうすればよいですか?

myObserver.prototype = {

 observe: function(subject, topic, data) {

  if("http-on-modify-request"){

    var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);

    if(httpChannel.requestMethod=="POST")
      alert(httpChannel.originalURI.spec);

       }
  }

},
register: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
                      .getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "http-on-modify-request", false);

},
unregister: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"]
                        .getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, "http-on-modify-request");
}
}

何か案は?

4

2 に答える 2

-1

Luckyrat のコードは、私には適切に機能しませんでした。いくつかのリクエストのタイムアウトに対処する必要がありました。nmaiers のコメントに注目すると、このコードは正しく機能しています (私が知る限り):

function getPostString(httpChannel) {
    var postStr = "";
    try {
        var uploadChannel = httpChannel.QueryInterface(Ci.nsIUploadChannel);
        var uploadChannelStream = uploadChannel.uploadStream;
        if (!(uploadChannelStream instanceof Ci.nsIMultiplexInputStream)) {
            uploadChannelStream.QueryInterface(Ci.nsISeekableStream).seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
            var stream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
            stream.setInputStream(uploadChannelStream);
            var postBytes = stream.readByteArray(stream.available());

            uploadChannelStream.QueryInterface(Ci.nsISeekableStream).seek(0, 0);

            postStr = String.fromCharCode.apply(null, postBytes);
        }
    }
    catch (e) {
        console.error("Error while reading post string from channel: ", e);
    }
    finally {
        return postStr;
    }
}
于 2014-01-19T02:19:23.443 に答える