本文介绍了cefsharp如何截获xhr请求以获取响应正文值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CefSharp是否能够拦截XHRHttpRequest并获取响应正文值?如果是,我想知道它是如何完成的.
Is CefSharp able to intercept XHRHttpRequest and obtain the response body value? if yes, I would like to know how it is done.
推荐答案
为此我创建了以下类,并从 IRequestHandler.GetResourceResponseFilter
返回它的实例:
I created the following class for this and return instance of it from 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;
}
}
这篇关于cefsharp如何截获xhr请求以获取响应正文值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!