简体   繁体   中英

how can cefsharp intercept xhr request to obtain response body value?

Is CefSharp able to intercept XHRHttpRequest and obtain the response body value? if yes, I would like to know how it is done.

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM