【问题标题】:Http Request Error when C# Project Target to .Net Framework 4.8 in Window 7Window 7 中 C# 项目目标为 .Net Framework 4.8 时的 Http 请求错误
【发布时间】:2021-06-10 06:16:54
【问题描述】:

我之前的 C# 项目目标是 .Net Framework 4.6.1,在窗口 7、8.1 和 10 中工作正常。但现在我将目标框架更改为 .Net Framework 4.8、Window 8.1 和 10 仍然没有问题,但窗口HTTP 请求中的 7 错误。

"An error occurred while making the HTTP request to https://Test.123.com/API/ServiceRouter.svc. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."

备注

  1. Http 请求操作只是从我的服务接收一些数据
  2. .Net Framework 4.8 已安装在 window 7 (SP 1) 平台中。
  3. 代码没有任何改变

【问题讨论】:

  • 我发现了这个问题,这是因为 .NET Framework 4.7 中默认使用 TLS1.0、1.1 和 1.2。从 .NET Framework 4.7.1 开始,默认为操作系统配置的版本。所以我需要在 HTTP 请求之前添加这段代码。 "System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;"" docs.microsoft.com/en-us/dotnet/framework/network-programming/…

标签: httprequest .net-framework-4.8


【解决方案1】:

伟大的周春。这段代码解决了我的问题:

"System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;"

谢谢。

【讨论】:

    猜你喜欢
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多