错误12175调用WINHTTP_CALLBACK_STATUS_REQUEST_ERROR发生安全错误

问题描述 投票:5回答:1

我已经在asp.net core 2.1中创建了网站。在此网站中,我们使用httpclient调用第三方HTTPS webapi。当我在Smarterasp.net共享托管服务器上部署时,我的网站工作正常,但是当我在Windows 2016服务器上使用代理设置部署时,它给出以下错误。这仅发生在HTTPS APi中。对于非https api,它可以在Windows Server 2016上正常工作。

登录失败异常System.Net.Http.HttpRequestException:发送请求时发生错误。 ---> System.Net.Http.WinHttpException:调用WINHTTP_CALLBACK_STATUS_REQUEST_ERROR的错误12175,“发生安全错误”。在System.Threading.Tasks.RendezvousAwaitable1.GetResult() at System.Net.Http.WinHttpHandler.StartRequest(WinHttpRequestState state) --- End of inner exception stack trace --- at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask,HttpRequestMessage请求,CancellationTokenSource cts,布尔值disposeCts]

我进行了一些研究,并在此基础上设置了以下代码,但仍然超出错误范围。对于非HTTPs api正常工作。

 AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
        var handler = new HttpClientHandler();
         if (ProxySettings.Current.UseProxy)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            handler.SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
            handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
            {
                return true;
            };

            var proxy = new WebProxy();
            if (!string.IsNullOrWhiteSpace(ProxySettings.Current.ProxyHost) && ProxySettings.Current.ProxyPort != 0)
            {
                proxy = new WebProxy(ProxySettings.Current.ProxyHost, ProxySettings.Current.ProxyPort);
            }
            proxy.UseDefaultCredentials = ProxySettings.Current.UseDefaultCredentials;
            if (!string.IsNullOrWhiteSpace(ProxySettings.Current.ProxyUrl))
                proxy.Address = new Uri(ProxySettings.Current.ProxyUrl);

            if (ProxySettings.Current.HasNetworkCredentials)
            {
                var credentials = new NetworkCredential();
                credentials.UserName = ProxySettings.Current.NetworkUserName;
                credentials.Password = ProxySettings.Current.NetworkPassword;
                if (!string.IsNullOrWhiteSpace(ProxySettings.Current.NetworkDomain)) credentials.Domain = ProxySettings.Current.NetworkDomain;

                proxy.Credentials = credentials;
            }

            handler = new HttpClientHandler
            {
                UseProxy = true,
                Proxy = proxy,
            };
        }

您能帮忙获得解决方案吗?

c# asp.net asp.net-core .net-core asp.net-core-2.1
1个回答
0
投票

有什么解决方案吗?对我来说这件事,现在很重要,23333

© www.soinside.com 2019 - 2024. All rights reserved.