Q:DotNetBrowser 是否支持socks5认证?

Q: Does DotNetBrowser support socks5 authentication?

使用此处提供的代码示例:https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110051-configuring-proxy 仅适用于 HTTP(S) 代理,不适用于 socks5。是否支持对 SOCKS 5 做同样的事情?谢谢

DotNetBrowser 基于 Chromium 引擎。不幸的是,Chromium 引擎不支持 SOCKS 5 身份验证,因此 DotNetBrowser 也不支持此类身份验证。

Chromium 错误跟踪器中存在问题:https://bugs.chromium.org/p/chromium/issues/detail?id=256785

一旦我们切换到支持 SOCKS 5 身份验证的 Chromium 版本,我们也会将此实现添加到 DotNetBrowser 中。

作为解决方法,您可以尝试创建自己的“IProtocolHandler”接口实现,以使用第 3 方库处理对所需代理服务器的请求。但是请注意,请求不能并行处理,因此性能可能会显着降低。

以下文章演示了如何注册自定义协议处理程序:https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000134504-custom-protocol-handler

根据 Eugene Yakush 的建议,我想到了这个:

    public class HttpsHandler : IProtocolHandler
{
    public string socksHost = string.Empty;
    public int socksPort = -100;
    public bool socksLogin = false;
    public string socksUsername = string.Empty;
    public string socksPassword = string.Empty;

    //This method should provide the response for the specified request
    private Chilkat.Http http;
    private Chilkat.HttpRequest httpRequest;
    private Chilkat.HttpResponse httpResponse;
    private Chilkat.Spider spider;
    public HttpsHandler()
    {
        this.http = new Chilkat.Http();
        this.spider = new Chilkat.Spider();
    }
    public IUrlResponse Handle(IUrlRequest request)
    {
        http.SocksHostname = socksHost;
        http.SocksPort = socksPort;
        http.SocksVersion = 5;
        if (socksLogin)
        {
            http.SocksUsername = socksUsername;
            http.SocksPassword = socksPassword;
        }
        httpRequest = new Chilkat.HttpRequest();
        httpRequest.HttpVerb = request.Method.ToUpper();
        Console.WriteLine(request.Url);

        if (request.Method.ToUpper() == "POST")
        {

            var xxl = request.PostData;
            PostData post = request.PostData;
            FormData postData = (FormData)post;
            var keys = postData.GetPairKeys();
            foreach (var item in keys)
            {
                var val = postData.GetPairValues(item);
                Console.WriteLine(item + ":" + val[0]);
                httpRequest.AddParam(item, val[0]);
            }
        }
        var heads = request.Headers.GetHeaders();
        foreach (KeyValuePair<string, List<string>> pair in heads)
        {
            httpRequest.AddHeader(pair.Key, pair.Value[0]);
            Console.WriteLine(pair.Key);
            Console.WriteLine(pair.Value[0]);
            Console.WriteLine("===================");
        }
        string path = request.Url;
        string domain = spider.GetUrlDomain(request.Url);
        path = path.Replace("https://" + domain, string.Empty);
        httpRequest.AddHeader("Host", domain);
        httpRequest.Path = path;
        httpResponse = http.SynchronousRequest(domain, 443, true, httpRequest);
        Console.WriteLine(httpResponse.StatusCode);
        if (httpResponse == null)
        {
            return new UrlResponse(Encoding.UTF8.GetBytes(string.Empty), (System.Net.HttpStatusCode)httpResponse.StatusCode);
        }
        return new UrlResponse(Encoding.UTF8.GetBytes(httpResponse.BodyStr), (System.Net.HttpStatusCode)httpResponse.StatusCode);
    }
}

显然可以简化。但如果有人有同样的问题,这就是我的解决方案。