CEFSharp-阅读网络回复 [英] CEFSharp - Read web responses

查看:82
本文介绍了CEFSharp-阅读网络回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,我想使用Chromium Web浏览器并能够读取通常通过DevTools网络"选项卡获得的数据.因此,基本上我真正需要的只是URL和状态代码(404、200、50x等).

I am working on a project that I want to use the Chromium Web Browser and be able to read the data that would normally come though the DevTools "Network" tab. So basically all i really need is the URL and the status code (404, 200, 50x, etc).

对于ChromiumWebBrowser部件,我一切正常,因为它可以正常工作,但我似乎无法弄清楚如何获取网络数据的详细信息.

I have everything working properly for the ChromiumWebBrowser part because that works perfectly but I cant seem to figure out the details on how to get the network data.

我在github的问题部分找到了这个,但是我不太了解如何实现它. https://github.com/cefsharp/CefSharp/issues/1379

I found this in a github issues section but I dont really understand how to implement it. https://github.com/cefsharp/CefSharp/issues/1379

任何帮助将不胜感激.

这是我到目前为止所拥有的...

Here is what I have so far...

private ChromiumWebBrowser _wb;

    public MainForm()
    {
        var cefsettings = new CefSettings { CachePath = "cache" };
        cefsettings.CachePath = "cache";
        if (cefsettings.CefCommandLineArgs.ContainsKey("enable-system-flash"))
        {
            string flashValue;
            cefsettings.CefCommandLineArgs.TryGetValue("enable-system-flash", out flashValue);
            if (flashValue != "1")
            {
                Debug.WriteLine("Flash Might Be Disabled For Chromium Web Browser");
            }
        }
        else
        {
            cefsettings.CefCommandLineArgs.Add("enable-system-flash", "1");
        }
        //TODO: Get the latest version version folder
        cefsettings.CefCommandLineArgs.Add("ppapi-flash-path","C:\\program Files (x86)\\Google\\Chrome\\Application\\51.0.2704.103\\PepperFlash\\pepflashplayer.dll");
        Cef.Initialize(cefsettings);

        InitializeComponent();

        _wb = new ChromiumWebBrowser("http://youtube.com/")
        {
            Dock = DockStyle.Fill,
            Location = new System.Drawing.Point(0, 22),
            MinimumSize = new System.Drawing.Size(20, 20),
            Size = new System.Drawing.Size(1280, 900),
            TabIndex = 8
        };

        //Add ChromiumWebBrowser to the Browser Panel
        pnlBrowser.Controls.Add(_wb);
    }

推荐答案

这就是我最终要做的...

Here is what I ended up doing...

实现了一个名为"RequestHandler"的类,该类实现了IRequestHandler接口.从CEFSharp开源项目中复制了该接口方法的大多数默认代码,然后根据自己的喜好对"IR​​equestHandler.OnResourceResponse"部分进行了调整.

Implemented a class called "RequestHandler" that implements the IRequestHandler interface. Copied most of the default code for this interfaces methods from the CEFSharp open source project and then just tweaked the "IRequestHandler.OnResourceResponse" portion to my liking.

然后在使用网络浏览器的主窗体上,我只使用了下面的代码...

Then on my main form that uses the web browser, I just used the code below...

//Create ChromiumWebBrowser
_wb = new ChromiumWebBrowser(Urls.HOME)
{
    Dock = DockStyle.Fill,
    Location = new System.Drawing.Point(0, 22),
    MinimumSize = new System.Drawing.Size(20, 20),
    Size = new System.Drawing.Size(1280, 900),
    TabIndex = 8
};

//Add ChromiumWebBrowser to the Browser Panel and add events
pnlBrowser.Controls.Add(_wb);
var requestHandler = new RequestHandler();
_wb.RequestHandler = requestHandler;

我希望这对某人有帮助!

I hope this helps someone!

这篇关于CEFSharp-阅读网络回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆