我在Visual Studio 2017中使用Twilio REST客户端。为simple SMS autoresponder添加Studio Flow后,我无法再使用Twilio REST API从我的ASP.net应用程序发送SMS消息。
错误消息是“需要升级”
at Twilio.Clients.TwilioRestClient.ProcessReponse(Reponse response)
at Twilio.Rest.Api.V2010.Account.MessageResource.Create(CreateMessageOptions options, ITwilioRestClient client)
at...
我已经尝试将Twilio REST API帮助程序库NuGet包升级到最新版本5.28.0。
此基本SMS发送代码的错误发生在以前工作。
Dim message = MessageResource.Create(body:=strBody, from:=New Twilio.Types.PhoneNumber(Credentials.TwilioFixityNewNumberFormatted), [to]:=New Twilio.Types.PhoneNumber(strFormattedNumber))
Return message.Sid
我的Twilio帐户中没有任何错误消息或通知表明存在错误或需要。有没有人经历过这样的事情?
似乎修改Twilio项目使其成为一个“新”项目,受到TLS 1.2要求的约束,这些要求刚刚于2009年3月28日实施。通过将Windows和.NET更新为最新更新并在访问Twilio REST API之前显式启用TLS 1.2来解决此问题:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 'Force TLS 1.2
当您使用旧的TLS版本时,Twilio将返回升级。使用ServicePointManager.SecurityProtocol
直接设置版本确实可以修复它,但这不是一个好主意,因为它会在发布新的TLS版本时变得过时。相反,请参阅Transport Layer Security (TLS) best practices with the .NET Framework,原因可能是它选择了旧版本。
在我的情况下,这是由于Web.config
中的这一行:
<httpRuntime targetFramework="4.5" />
将其设置为我正在使用的实际.NET Framework版本修复了Twilio错误。