This isn’t an unusual error, you can find a lot of answers on Stack Overflow, for example.

For me I was using a simple

WebClient client = new WebClient();

With a send like this:

Stream data = client.OpenRead(arguments);
StreamReader reader = new StreamReader(data_to_send);
s = reader.ReadToEnd();

And getting the error in the title. It said that the endpoint had terminated the connection. Why would they do that?

TLS

So it seems that I was using a TLS version lower than the endpoint required.

You should be able to set it like this:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12;

As per this answer

However, if you’re using an old, old .NET version or Server 2008 for example, then you don’t have these enumerations, but don’t worry, you can set it like this:

ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // 1.1=768, 1.2=3072 TLS versions WebClient client = new WebClient();

Where that 3072 = TLS 1.2, and 768 = TLS 1.1.

Last modified: May 22, 2019

Author

Comments

Write a Reply or Comment

Your email address will not be published.