Twitter API 回复 'An existing connection was forcibly closed by the remote host'
Twitter API responds with 'An existing connection was forcibly closed by the remote host'
我公司有一些 dotNET 代码,在过去三个月中一直在与 Twitter 的 API 愉快地交谈,在推特上发布我们的新闻。
7 月 29 日它停止工作,POST 请求遇到此错误:
An existing connection was forcibly closed by the remote host
System.Net.Sockets.SocketException
我认为这是因为我们的服务器仍在使用 TLS 1.1,而我只是从 6 月才发现 this Twitter API announcement,它说:
Since the removal of SSL support 104 in 2014, the Twitter API has
required a minimum of TLS 1.0 for all incoming connections. Both TLS
1.0 and 1.1 were superseded by TLS 1.2 in 2008.
Beginning July 25th 2019, all connections to the Twitter API (and all
other Twitter domains) will require TLS 1.2. This change will affect
all formats and tiers of the API (REST, streaming, and webhooks;
standard, premium, enterprise, and Ads and Media APIs), as well as the
wider Twitter platform.
看来我们有 4 天的宽限期,因为我们的代码在 7 月 25 日到 28 日之间没有问题。
我相信服务器本身已经安装了 TLS 1.2,所以问题可能是这个项目是用默认使用 TLS 1.1 的 dotNET 4.0 编译的?
将我们的项目升级到 dotNET 4.5 是否可以解决问题,还是其他问题?
我也是 7 月 29 日开始的同样问题。我的项目使用 .NET 4.5.2 编译并使用 LinqToTwitter 库。我能够通过在拨打 Twitter 电话之前添加以下行来解决问题。
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
我是来安装dotNET 4.5的,给了repair/remove的选项,说明已经安装了!这是出乎意料的。
所以我添加了这行代码:
System.Net.ServicePointManager.SecurityProtocol = 3072
并将 Web.config 更改为使用 targetFramework="4.5"
现在一切都恢复正常了。谢谢
我自己也遇到了同样的问题。但是,请注意对 ServicePointManager
的更改将应用于所有端点。因此,如果您连接到另一个不支持 TLS 1.2 的设备,它将停止工作。
因此,更好的解决方案是 或 Tls12
值与现有值。
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
同样的问题。 Twitter 调用 ExternalLogin 时调用失败。我认为这是一个 TLS 1.2 问题。由于用户未通过身份验证,因此此处失败(请参见下面的代码)。 Facebook Auth 不会触发新的 ChallengeResult,所以我知道它应该是这样工作的。
if (!User.Identity.IsAuthenticated)
{
return new ChallengeResult(provider, this);
}
我的 Asp.Net Web API 已经针对 4.6.1,但运行时配置为 4.5。我的解决方法是更新 Web.config 中的这一行并重建应用程序。
<system.Web>
<httpRuntime targetFramework="4.6.1" />
</system.Web>
进行此更改后,Twitter 身份验证 window 再次显示。
注意:我在别处读到您不应该乱用 System.Net.ServicePointManager.SecurityProtocol 设置。 Asp.Net 4.6.1 默认为 TLS 1.2,但它应该向后兼容 1.1 和 1.0。我即将测试一些使用此 API 的 Xamarin 应用程序,所以我会让每个人都知道会发生什么。即将更新!
我公司有一些 dotNET 代码,在过去三个月中一直在与 Twitter 的 API 愉快地交谈,在推特上发布我们的新闻。
7 月 29 日它停止工作,POST 请求遇到此错误:
An existing connection was forcibly closed by the remote host
System.Net.Sockets.SocketException
我认为这是因为我们的服务器仍在使用 TLS 1.1,而我只是从 6 月才发现 this Twitter API announcement,它说:
Since the removal of SSL support 104 in 2014, the Twitter API has required a minimum of TLS 1.0 for all incoming connections. Both TLS 1.0 and 1.1 were superseded by TLS 1.2 in 2008.
Beginning July 25th 2019, all connections to the Twitter API (and all other Twitter domains) will require TLS 1.2. This change will affect all formats and tiers of the API (REST, streaming, and webhooks; standard, premium, enterprise, and Ads and Media APIs), as well as the wider Twitter platform.
看来我们有 4 天的宽限期,因为我们的代码在 7 月 25 日到 28 日之间没有问题。
我相信服务器本身已经安装了 TLS 1.2,所以问题可能是这个项目是用默认使用 TLS 1.1 的 dotNET 4.0 编译的?
将我们的项目升级到 dotNET 4.5 是否可以解决问题,还是其他问题?
我也是 7 月 29 日开始的同样问题。我的项目使用 .NET 4.5.2 编译并使用 LinqToTwitter 库。我能够通过在拨打 Twitter 电话之前添加以下行来解决问题。
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
我是来安装dotNET 4.5的,给了repair/remove的选项,说明已经安装了!这是出乎意料的。
所以我添加了这行代码:
System.Net.ServicePointManager.SecurityProtocol = 3072
并将 Web.config 更改为使用 targetFramework="4.5"
现在一切都恢复正常了。谢谢
我自己也遇到了同样的问题。但是,请注意对 ServicePointManager
的更改将应用于所有端点。因此,如果您连接到另一个不支持 TLS 1.2 的设备,它将停止工作。
因此,更好的解决方案是 或 Tls12
值与现有值。
System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;
同样的问题。 Twitter 调用 ExternalLogin 时调用失败。我认为这是一个 TLS 1.2 问题。由于用户未通过身份验证,因此此处失败(请参见下面的代码)。 Facebook Auth 不会触发新的 ChallengeResult,所以我知道它应该是这样工作的。
if (!User.Identity.IsAuthenticated)
{
return new ChallengeResult(provider, this);
}
我的 Asp.Net Web API 已经针对 4.6.1,但运行时配置为 4.5。我的解决方法是更新 Web.config 中的这一行并重建应用程序。
<system.Web>
<httpRuntime targetFramework="4.6.1" />
</system.Web>
进行此更改后,Twitter 身份验证 window 再次显示。
注意:我在别处读到您不应该乱用 System.Net.ServicePointManager.SecurityProtocol 设置。 Asp.Net 4.6.1 默认为 TLS 1.2,但它应该向后兼容 1.1 和 1.0。我即将测试一些使用此 API 的 Xamarin 应用程序,所以我会让每个人都知道会发生什么。即将更新!