CefSharp 3在运行时设置代理 [英] CefSharp 3 set proxy at Runtime

查看:95
本文介绍了CefSharp 3在运行时设置代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了(cefclient& cefsimple)c ++示例附带的CEF(chromium嵌入式框架)二进制分发版,并意识到cefclient可以在运行时更改代理设置。

I downloaded CEF (chromuim embedded framework) binary distributation that comes with (cefclient & cefsimple) c++ examples, And Realized that cefclient can change proxy settings on run-time.

要做的关键是抓住RequestContext并调用函数SetPreference。

And the key to do that is to Grab the RequestContext and call the function SetPreference.

都很好用。

,但是在CefSharp上调用SetPreference始终返回false,并且HasPreference也为首选名称 proxy返回false。

but on CefSharp calling SetPreference always returns false, and also HasPreference returns false for the preference name "proxy".

推荐答案

感谢 amaitland 积极强制更改请求上下文首选项的正确方法是在以下位置运行代码CEF UIThread如下:

thanks to amaitland the proper way to actively inforce changing the request-context prefrences, is to run the code on CEF UIThread as following:

    Cef.UIThreadTaskFactory.StartNew(delegate {
        var rc = this.browser.GetBrowser().GetHost().RequestContext;
        var v = new Dictionary<string, object>();
        v["mode"] = "fixed_servers";
        v["server"] = "scheme://host:port";
        string error;
        bool success = rc.SetPreference("proxy", v, out error);
        //success=true,error=""
    });

这篇关于CefSharp 3在运行时设置代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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