Benjo
Benjo

Reputation: 189

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

On one particular website on my web server WebRequests have started throwing the following error: "The underlying connection was closed: An unexpected error occurred on a send."

Request code:

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

I have tried adding the following to the page doing the request, and the global.asax, but it did not work. It should not be required, though, because I am using .net 4.8:

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

Upvotes: 0

Views: 1285

Answers (1)

Richard Deeming
Richard Deeming

Reputation: 31198

As mentioned in the comments, this is often an issue with the internal DNS or a HOSTS file entry. Either the server is resolving the site's domain to the wrong internal address, or it's trying to access the site's public address and confusing the router.

Upvotes: 1

Related Questions