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



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

  • 我的asp。. NET网站正在运行框架版本4.8。
  • 我正在请求同一网站上的页面。
  • 这个代码已经存在多年了,突然停止在这个网站上工作
  • 相同的代码在同一web服务器上运行的不同网站上运行良好

请求代码:

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()

我已经尝试将以下内容添加到正在执行请求的页面,以及全局。Asax,但它没有工作。但是,它不应该是必需的,因为我使用的是。net 4.8:

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

正如评论中提到的,这通常是内部DNS或HOSTS文件条目的问题。要么是服务器将站点的域解析为错误的内部地址,要么是它试图访问站点的公共地址,从而混淆了路由器。

相关内容

最新更新