The underlying connection was closed an unexpected error occurred on a send

Hi,

Today I was working on calling some external url via C# code using HttpRequest and I was continuously getting the below error.

The underlying connection was closed an unexpected error occurred on a send.

There could be multiple reasons for this but adding the below line before sending the request helped to fix the issue.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12


Hope this helps.


Happy Coding

Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s