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

喜夏-厌秋 提交于 2020-01-15 18:47:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!