1
httpリクエストをトラップし、ポストパラメータの一部を変更して変更されたリクエストを送信しようとしています。 アップロードストリームのsetDataメソッドを使用してリクエストを変更しようとしましたが、同じ元のリクエストが送信されました。Firefoxの拡張機能でリクエストの投稿データを変更します
私は次のコードは、「HTTP-にモディファイ要求」上で実行している:
//rewind the request to read post body
channel= subject.QueryInterface(Components.interfaces.nsIHttpChannel);
channel=channel.QueryInterface(Components.interfaces.nsIUploadChannel);
channel = channel.uploadStream;
channel.QueryInterface(Components.interfaces.nsISeekableStream)
.seek(Components.interfaces.nsISeekableStream.NS_SEEK_SET, 0);
var stream = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
stream.setInputStream(channel);
var postBytes = stream.readByteArray(stream.available());
poststr = String.fromCharCode.apply(null, postBytes);
//change the poststr
poststr=poststr.replace(....);
stringStream.setData(poststr, poststr.length);
//changing the postdata
channel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);
channel = channel.uploadStream;
channel = channel.QueryInterface(Components.interfaces.nsISeekableStream)
.seek(Components.interfaces.nsISeekableStream.NS_SEEK_SET, 0);
channel.uploadStream.QueryInterface(Components.interfaces.nsIMIMEInputStream);
channel.uploadStream.setData(stringStream);
channel.send();
は、私がここで間違って何をしているのですか? 私は最初のリクエストを中止して、新しいリクエストから始めましたが、ページがまったく読み込まれませんでした。 Thanxは事前に
質問をするときに、コードをコードのように見せるために '{}'ボタンを使うことができます。 – MatrixFrog
http-on-modify-requestから 'channel.send'を明示的に呼び出す必要はありません.Firefoxはあなたのコードを呼び出した後にそれを行います。あなたはそれを取って、それが何か変わるかどうかを調べることができます。 – MatrixFrog