asp.NET 4.8 WebRequest 错误 "The underlying connection was closed: An unexpected error occurred on a send."

asp.NET 4.8 WebRequest errors with "The underlying connection was closed: An unexpected error occurred on a send."

在我的网络服务器上的一个特定网站上,WebRequests 开始抛出以下错误:“底层连接已关闭:发送时发生意外错误。”

请求代码:

Dim myReq As System.Net.WebRequest = System.Net.WebRequest.Create("https://example.com")
myReq.Method = "GET"

myReq.ContentType = "text/html; encoding='utf-32'"


Dim wr As System.Net.WebResponse = myReq.GetResponse()
Dim receiveStream As System.IO.Stream = wr.GetResponseStream()
Dim reader As System.IO.StreamReader = New System.IO.StreamReader(receiveStream, Encoding.UTF8)
Dim content As String = reader.ReadToEnd()

我已经尝试将以下内容添加到执行请求的页面和 global.asax,但没有成功。不过,这不是必需的,因为我使用的是 .net 4.8:

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

如评论中所述,这通常是内部 DNS 或 HOSTS 文件条目的问题。服务器要么将站点的域解析为错误的内部地址,要么试图访问站点的 public 地址并混淆了路由器。