使用此处提供的代码示例:https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110051-configuring-proxy仅适用于HTTP(S)代理,但不适用于socks5。是否支持为SOCKS 5做同样的事情?感谢
答案 0 :(得分:1)
DotNetBrowser基于Chromium引擎。遗憾的是,Chromium引擎不支持SOCKS 5身份验证,因此DotNetBrowser也不支持此类身份验证。
Chromium bug跟踪器存在问题:https://bugs.chromium.org/p/chromium/issues/detail?id=256785
一旦我们切换到可以获得SOCKS 5身份验证支持的Chromium版本,我们也会将此实现添加到DotNetBrowser中。
作为解决方法,您可以尝试创建自己的“IProtocolHandler”接口实现,以使用第三方库处理对所需代理服务器的请求。但请注意,请求无法并行处理,因此性能可能会大幅降低。
以下文章演示了如何注册自定义协议处理程序:https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000134504-custom-protocol-handler
答案 1 :(得分:0)
根据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);
}
}
显然,它可以简化。但如果有人遇到同样的问题,这就是我的解决方案。