问题
Is CefSharp able to intercept XHRHttpRequest and obtain the response body value? if yes, I would like to know how it is done.
回答1:
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;
}
}
来源:https://stackoverflow.com/questions/42497464/how-can-cefsharp-intercept-xhr-request-to-obtain-response-body-value