CefSharp是否能够拦截XHRHttpRequest并获取响应体值?如果是的话,我想知道它是如何完成的。
答案 0 :(得分:0)
我为此创建了以下类,并从IRequestHandler.GetResourceResponseFilter
返回了它的实例:
internal class ResponseSniffer : IResponseFilter
{
private readonly Action<Stream> _streamHandler;
public ResponseSniffer(Action<Stream> streamHandler)
{
_streamHandler = streamHandler;
}
public void Dispose()
{
}
public bool InitFilter()
{
return true;
}
public FilterStatus Filter(Stream dataIn, out long dataInRead, Stream dataOut, out long dataOutWritten)
{
if (dataIn == null)
{
dataInRead = 0;
dataOutWritten = 0;
return FilterStatus.Error;
}
dataIn.CopyTo(dataOut);
dataInRead = dataIn.Length;
dataOutWritten = dataInRead;
dataIn.Position = 0;
_streamHandler(dataIn);
return FilterStatus.Done;
}
}