CefSharp 3 在运行时设置代理

编程入门 行业动态 更新时间:2024-10-22 23:09:04
本文介绍了CefSharp 3 在运行时设置代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我下载了 (cefclient & cefsimple) c++ 示例附带的 CEF(chromuim 嵌入式框架)二进制分发版,并意识到 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.

在 CefClient 上一切正常.

on CefClient all works just nice.

但是在 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 在运行时设置代理

本文发布于:2023-06-10 22:53:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620817.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CefSharp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!