繁体   English   中英

如何在 .NET Core http 客户端中禁用 SSL 证书检查?

[英]How can I disable the SSL Certificate check in the .NET Core http client?

我正在尝试通过代理连接到网站。 这发生在 AWS Lambda 和 .NET Core SDK 使用 Z80791B3AE7002CB88C246876D9FAAF8 客户端。 调用看起来很像这样:

handler = new HttpClientHandler()
{
 CookieContainer = cookieContainer,
     Proxy = new WebProxy(
                new Uri(Environment.GetEnvironmentVariable("proxyURL"))),
     ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator,
     SslProtocols = SslProtocols.Tls12,
     ClientCertificateOptions = ClientCertificateOption.Manual
};

using(var client = new HttpClient(handler))
{
     var content = await client.GetAsync("https://my-website.com/");
}

我无法拨打“https://my-website.com/”电话。 调用超时,没有错误消息。

但是,我能够使用 Golang 访问该网站,并在 AWS Lambda 中休息,跳过 TLS 检查:

client := resty.New()
resp, err := client.
    SetProxy(os.Getenv("proxyURL")).
    SetRetryCount(3).SetTimeout(3*time.Second).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}).
    R().Get("https://my-website.com/")

我的问题是:如何在 .NET 核心代码中实现 Golang 代码的行为?

TL; DR:问题不在于证书验证,而在于安全组规则。

  1. 正如Marc Gravell所指出的, DangerousAcceptAnyServerCertificateValidator已经达到了忽略证书验证问题的目的。
  2. 在同一 VPC 和子网中的 EC2 实例中部署相同的代码后,我注意到 .NET 核心代码比 Go 代码多发出一次 HTTP 调用(尽管我仍然不明白为什么)。 IP 地址不在允许的 IP 传出流量范围内,因此阻塞了请求并导致HttpClient超时。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM