Twitter API responds with 'An existing connection was forcibly closed by the remote host'
I had the same issue start on July 29th as well. My project is compiled with .NET 4.5.2 and uses the LinqToTwitter library. I was able to fix the problem by adding the following line prior to making Twitter calls.
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
I came to install dotNET 4.5 and was given the options to repair/remove, indicating it was already installed! This was unexpected.
So I added this line of code:
System.Net.ServicePointManager.SecurityProtocol = 3072
And changed Web.config to use targetFramework="4.5"
Everything now working again. Thanks.
Just had the same issue myself. However, beware that the change to ServicePointManager
will apply to all endpoints. So, if you are connecting to another that doesn't support TLS 1.2, it will stop working.
So, a better solution would be to or the Tls12
value with the existing value.
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;