cefsharp 使用代理切换ip
1.Program.cs 设置不代理
settings.CefCommandLineArgs.Add("no-proxy-server", "1");//不使用代理
2.编写方法:
async private void SetProxy(ChromiumWebBrowser cwb, string Address)
{
await Cef.UIThreadTaskFactory.StartNew(delegate
{
var rc = cwb.GetBrowser().GetHost().RequestContext;
var v = new Dictionary();
v[“mode”] = “fixed_servers”;
v[“server”] = Address;
string error;
bool success = rc.SetPreference(“proxy”, v, out error);
});
}
然后每次更新换代理ip时调用该方法就可以,如下:
SetProxy(CefBrowser, 新代理ip及端口);
CefSharp.CefSharpSettings.Proxy = new CefSharp.ProxyOptions(新代理ip, 端口, 用户名,密码);