cefsharp proxy authentication required

匿名 (未验证) 提交于 2019-12-03 01:27:01

问题:

i'm trying to use proxy with Auth on cefsharp i tried this code and it's working with proxy without Auth only what should i do to set Auth .

Cef.UIThreadTaskFactory.StartNew(delegate                     {                         string ip = "IP";                         string port = "PORT";                         var rc = chrome.GetBrowser().GetHost().RequestContext;                         var dict = new Dictionary();                         dict.Add("mode", "fixed_servers");                         dict.Add("server", "" + ip + ":" + port + "");                         string error;                         bool success = rc.SetPreference("proxy", dict, out error);                     }); 

i found this link but i don't understand how to do it

https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage.md#markdown-header-proxy-resolution please write some code i'm beginer.

回答1:

I'm back with a real answer this time.

What you need to do is to implement your own class using IRequestHandler and call the GetAuthCredentials().

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;       } } 

The callback.Continue() will apply the credentials for you when called.

You then implement the handler to your browser instance in the code you allready have.

Cef.UIThreadTaskFactory.StartNew(delegate {        chrome.RequestHandler = new MyRequestHandler();        string ip = "IP";       string port = "PORT";       var rc = chrome.GetBrowser().GetHost().RequestContext;       var dict = new Dictionary();       dict.Add("mode", "fixed_servers");       dict.Add("server", "" + ip + ":" + port + "");       string error;       bool success = rc.SetPreference("proxy", dict, out error); }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!