繁体   English   中英

条纹支付:System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道

[英]Stripe Payment: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel

我在 WebAPI 2.0 中使用 C# rest API; 生成此异常的请求很少。 查找以下详细信息:

.net 版本:4.0 Stripe.net 版本:34.20.0.0 异常日志:

2020-02-18 06:47:45.4533|DEBUG|Services.impl.StripePaymentChargeService|System.Net.WebException: The 

request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
2020-02-18 06:47:45.4533|DEBUG|Services.impl.StripePaymentChargeService|   at Stripe.SystemNetHttpClient.<MakeRequestAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Stripe.StripeClient.<RequestAsync>d__25`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Stripe.Service`1.<RequestAsync>d__24`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Stripe.Service`1.Request[T](HttpMethod method, String path, BaseOptions options, RequestOptions requestOptions)
   at Stripe.ChargeService.Create(ChargeCreateOptions options, RequestOptions requestOptions)

我尝试过的事情:

1. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
           | SecurityProtocolType.Tls11
           | SecurityProtocolType.Tls12
           | SecurityProtocolType.Ssl3;



2.  ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

                System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                        delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                               System.Security.Cryptography.X509Certificates.X509Chain chain,
                                               System.Net.Security.SslPolicyErrors sslPolicyErrors)
                        {
                            return true; 

                        };

3. ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

            System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                    delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                           System.Security.Cryptography.X509Certificates.X509Chain chain,
                                           System.Net.Security.SslPolicyErrors sslPolicyErrors)
                    {
                        return true; 
                    };

条纹创建收费代码:

 stripeCharge = chargeService.Create(myCharge);

由于生产依赖性,我无法升级 .net 版本。 任何帮助,将不胜感激。

我认为你在这里有解决方案,不是投票的答案,而是它下面的答案:

.NET Framework 4.0 中的 TLS 1.2

基本上,您应该在应用程序启动时添加这一行,并确保目标机器上安装了 .net4.5:

ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;

*STRIPE 支付网关仅支持 TLS 1.1、TLS 1.2。

如果您的操作系统较旧且不支持 TLS,您也必须升级操作系统。 然后代码应该升级到 .net 4.5 或更高版本。 如果您无法将 .net 框架升级到 4.5,我为您提供了更复杂的解决方案。 使用自包含部署将代码转换为 ASp.net 核心。 https://gunnarpeipman.com/visual-studio-publish-self-contained-aspnet-core-azure-appservice/

创建一个 .net 核心解决方案,它可以在其 Publish 自包含容器中运行。 https://docs.microsoft.com/en-us/dotnet/core/deploying/

所以你有没有 .net 4.5 的操作系统的 .net 4.5 解决方案。 发布自包含将您的应用程序发布为自包含会生成特定于平台的可执行文件。 输出发布文件夹包含应用程序的所有组件,包括 .NET Core 库和目标运行时。 该应用与其他 .NET Core 应用隔离,并且不使用本地安装的共​​享运行时。 应用的用户不需要下载和安装 .NET Core。

可执行二进制文件是为指定的目标平台生成的。 例如,如果您有一个名为 word_reader 的应用程序,并且您发布了一个适用于 Windows 的自包含可执行文件,则会创建一个 word_reader.exe 文件。 对于 Linux 或 macOS 发布,会创建一个 word_reader 文件。 目标平台和体系结构使用 dotnet publish 命令的 -r 参数指定。 有关 RID 的详细信息,请参阅 .NET Core RID 目录。

如果应用程序具有特定于平台的依赖项,例如包含特定于平台的依赖项的 NuGet 包,则这些依赖项将与应用程序一起复制到发布文件夹。

暂无
暂无

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

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