无法在 C# 中使用 twilio 发送短信

Moh*_*003 3 .net c# twilio

我尝试使用 twilio 网站上的示例代码发送短信,但收到错误“TLS 协议无效”。我使用了有效的 accountid、authtoken 和经过验证的手机号码。

class Program
{
    static void Main(string[] args)
    {
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var message = MessageResource.Create(
            body: "Hi there",
            from: new Twilio.Types.PhoneNumber("+15017122661"),
            to: new Twilio.Types.PhoneNumber("+15558675310")
        );

        Console.WriteLine(message.Sid);
    }
}
Run Code Online (Sandbox Code Playgroud)

Meh*_*avi 6

显然,通过在发送请求之前将此行添加到代码中即可修复。要查看更多信息,请转至此链接中的相关问题:

https 端点的 Http 客户端

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Run Code Online (Sandbox Code Playgroud)