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();
내가 잘못 여기서 뭐하는 거지? 초기 요청을 중단하고 새로운 요청으로 시작했지만 페이지가 전혀로드되지 않습니다. 고맙습니다.
질문 할 때 코드처럼 보이는 코드를 만들기 위해'{}'버튼을 사용할 수 있습니다. – MatrixFrog
http-on-modify-request에서 'channel.send'를 명시 적으로 호출 할 필요가 없습니다. Firefox는 코드를 호출 한 후에이를 수행합니다. 당신은 그것을 꺼내보고 그것이 무엇이 바뀌는지를 볼 수 있습니다. – MatrixFrog