HttpHandler并自己设置证书来跳过这个问题。
通过这种解决方案,我对所有这些域名都得到了301 ,这感觉像是我的AllowAutoRedirect为false,但实际上并非如此。我尝试将MaxAutomaticRedirections指定为5,但也没有起作用。
以下是我的代码:
public Task<int> Crawl(string userAgent, string url)
{
var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
};
var httpClient = new HttpClient(handler);
httpClient.DefaultRequestHeaders.Add("User-Agent", userAgent);
var statusCode = (int)(await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, URL))).StatusCode;
return statusCode;
}
ClientCertificationOption.Manual吗? - keenthinker