需要cefsharp代理身份验证 [英] cefsharp proxy authentication required

查看:730
本文介绍了需要cefsharp代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在cefsharp
i上将Proxy与Auth一起使用,并且尝试了不使用Auth的Proxy,只有
才可以使用Auth进行设置。

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<string, object>();
                        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
请写一些我是初学者的代码。

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

推荐答案

这次我回来了。

您需要做的是实现自己的类使用IRequestHandler并调用GetAuthCredentials()。

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;

     }
}

callback.Continue()将

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<string, object>();
      dict.Add("mode", "fixed_servers");
      dict.Add("server", "" + ip + ":" + port + "");
      string error;
      bool success = rc.SetPreference("proxy", dict, out error);
});

这篇关于需要cefsharp代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆