- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我需要升级 .NET 应用程序以支持在仅支持 TLS 1.2 的网站上调用 API。据我了解,如果应用程序的目标是 4.6 或更高版本,那么它将默认使用 TLS 1.2。
为了测试,我创建了一个面向 4.7 的 Windows 窗体应用程序。不幸的是,当我没有明确设置 ServicePointManager.SecurityProtocol 时它会出错。这是代码:
HttpClient _client = new HttpClient();
var msg = new StringBuilder();
// If I uncomment the next line it works, but fails even with 4.7
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://sandbox.authorize.net");
httpWebRequest.KeepAlive = false;
try
{
var httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
msg.AppendLine("The HTTP request Headers for the first request are: ");
foreach (var header in httpWebRequest.Headers)
{
msg.AppendLine(header.ToString());
}
ResponseTextBox.Text = msg.ToString();
}
catch (Exception exception)
{
ResponseTextBox.Text = exception.Message;
if (exception.InnerException != null)
{
ResponseTextBox.Text += Environment.NewLine + @" ->" + exception.InnerException.Message;
if (exception.InnerException.InnerException != null)
{
ResponseTextBox.Text += Environment.NewLine + @" ->" + exception.InnerException.InnerException.Message;
}
}
}
如果您取消注释掉以下行:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
它有效。这不是一个好的解决方案,因为它硬编码了要使用的 TLS 版本,因此将来不会使用 TLS 1.3。
如果没有这条线,我还需要做什么才能让它工作。我正在从安装了 4.7 的 Window 10 机器上进行测试。
更新
我尝试使用 HttpClient 进行测试并得到相同的结果,我必须显式设置 SecurityProtocol。
代码:
var msg = new StringBuilder();
// Need to uncomment code below for TLS 1.2 to be used
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
try
{
var response = await _client.GetAsync(@"https://sandbox.authorize.net");
msg.AppendLine("response.IsSuccessStatusCode : " + response.IsSuccessStatusCode);
msg.AppendLine(await response.Content.ReadAsStringAsync());
textBox.Text = msg.ToString();
}
catch (Exception exception)
{
textBox.Text = exception.Message;
if (exception.InnerException != null)
{
textBox.Text += Environment.NewLine + @" ->" + exception.InnerException.Message;
}
}
最佳答案
我在针对 4.7.2 的旧版应用程序中遇到了同样的问题(仅限 Windows 10 和 SSL3/TLS……不是系统默认值)。我的问题是,在多年来的升级过程中,我们从未将 targetFramework
添加到 system.web
> httpRuntime
元素(注意:它确实存在于 system.web
> compilation
元素上)。在采取更大的步骤之前,确保您的 system.web 看起来像下面这样:
<system.web>
<compilation targetFramework="4.7.2"></compilation>
<httpRuntime targetFramework="4.7.2" />
</system.web>
在上面的示例中,将 4.7.2 替换为您当前使用的 >= 4.7 的框架版本。
关于c# - 在没有显式 ServicePointManager.SecurityProtocol 调用的情况下,.NET 4.7 中未协商 TLS 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44751179/
我正在尝试遵循与 How does System.Net.Mail.SMTPClient do its local IP binding 中给出的代码类似的代码。我在具有多个 IP 地址的机器上使用
我们有一个网站,每秒调用 Azure 存储数千次。所有存储端点都是 HTTPS。有谁知道设置 ServicePointManager.SetTcpKeepAlive = true 是否有助于提高性能?
我们有一个网站,每秒调用 Azure 存储数千次。所有存储端点都是 HTTPS。有谁知道设置 ServicePointManager.SetTcpKeepAlive = true 是否有助于提高性能?
目前刚刚了解 Windows Azure。 我正在查看一些示例,并且在我看到的辅助角色的 OnStart 事件 ServicePointManager.DefaultConnectionLimit =
我有一个 Xamarin.Forms 应用程序,它利用 ServicePointManager.ServerCertificateValidationCallback 类和方法实现证书固定。在 And
我需要使用多个任务来达到网络服务端点。每个任务都将流式传输数据,并打开一个 httpWebRequest 连接。 我需要将属性 ServicePointManager.DefaultConnectio
我在 azure 中作为 webjob 运行的控制台应用程序中调用了这行代码 50000 次: await cloudBlockBlob.UploadFromFileAsync(sourceFile)
有人可以解释一下 ServicePointManager.FindServicePoint 的用途吗?我一直在编写一些代码来使用 C# 中的代理,并且已经看到它在这方面可能有用的指标,但看不出为什么或
我想知道当我在她的标志上设置三个不同的 SecurityProtocolType 时属性 ServicePointManager.SecurityProtocol 是如何工作的。即: ServiceP
更改 ServicePointManager.DefaultConnectionLimit 是只影响当前进程还是影响整个 .NET 平台。请提供来源。 最佳答案 ServicePointManager
最近,我在发送电子邮件时遇到错误: The remote certificate is invalid according to the validation procedure using 我找到了
我在我的网站中使用网络服务。供应商提供了一个示例代码,在代码中有这样一行: // For Ignore SSL Error ServicePointManager.ServerCertificateV
我有以下代码。 public void Submit(string XML) { ServicePointManager.ServerCertificateValidationCallback = V
下面的代码是如何求值的? ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificateA;
ServicePointManager.DefaultConnectionLimit 设置辅助角色的最大并发 session 数,但如何找到最佳值? 最佳答案 根据Microsoft Support
如果我的机器上运行着2个Asp.Net网站,并且打开了2个PowerShell窗口,那么有多少个静态类System.Net.ServicePointManager实例? 每台机器一台?每个应用程序域一
默认情况下,HttpClient 每个主机仅使用 2 个并发连接。根据 docs我可以改变这一点。我不想在全局范围内更改它,我只想为我正在使用的服务更改它。因此我写了以下代码: // Increase
我正在使用一个应用程序,该应用程序每分钟向不同的 URI 发送数百个 HTTP 请求。有什么方法可以监控应用程序创建的连接吗?我发现 ServicePointManager 非常适合检查特定域,但它需
在 .NET 4.5 中,如果我将 ServicePointManager.SecurityProtocol 设置为多个协议(protocol)并且服务器接受所有这些协议(protocol),将使用哪
我正在尝试将 VB.net 项目转换为用于 Android 应用程序的 Java。我在某个时候卡住了。我的 VB.net 代码是 Public Function SendWebRequest(ByVa
我是一名优秀的程序员,十分优秀!