[英]cefsharp proxy authentication required
我正試圖在cefsharp上使用Auth的代理我嘗試了這個代碼,它正在使用沒有Auth的代理,我應該怎么做才能設置Auth。
Cef.UIThreadTaskFactory.StartNew(delegate
{
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);
});
我發現這個鏈接,但我不明白該怎么做
https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage.md#markdown-header-proxy-resolution請寫一些我喜歡的代碼。
這一次,我回來了一個真實的答案。
您需要做的是使用IRequestHandler實現您自己的類並調用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;
}
}
callback.Continue()將在調用時為您應用憑據。
然后,您可以在已有的代碼中將處理程序實現到瀏覽器實例。
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);
});
我使用cefsharp版本65,只需使用此代碼:
CefSharpSettings.Proxy = new ProxyOptions(ip: "myipaddress", port: "myport", username: "myusername", password: "mypassword");
把它放在Cef.Initialize()之前,它適用於我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.