I have a browser with multiple tabs. I want to set proxy for each tab with authantication. this is the code that i have.
CefSharpSettings.Proxy = new ProxyOptions(ip: ip, port: port, username: user, password: pass);
if (Cef.IsInitialized != true)
{
Cef.Initialize(new CefSettings());
}
browsers = new ChromiumWebBrowser(url);
the problem is that this code allows to set proxy once. there is some solutions like this.
Cef.UIThreadTaskFactory.StartNew(delegate
{
chrome.RequestHandler = new MyRequestHandler();
string ip = "IP";
string port = "PORT";
var rc = chrome.GetBrowser().GetHost().RequestContext;
var dict = new Dictionary<string, object>();
dict.Add("mode", "fixed_servers");
dict.Add("server", "" + ip + ":" + port + "");
string error;
bool success = rc.SetPreference("proxy", dict, out error);
});
and this class
public class MyRequestHandler : IRequestHandler
{
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
{
if (isProxy == true)
{
callback.Continue("Username", "Password");
return true;
}
return false;
}
}
but I get error on this line" public class MyRequestHandler : IRequestHandler" which tells:
Severity Code Description Project File Line Suppression State
Error CS0535 'browser.MyRequestHandler' does not implement interface member 'IRequestHandler.OnBeforeBrowse(IWebBrowser, IBrowser, IFrame, IRequest, bool, bool)' WindowsFormsApp1
Comments
Post a Comment