3

I tried to send SMS using the sample code from the twilio website but I am getting an error "Invalid TLS protocol". I had used valid accountsid, authtoken and verified mobile numbers.

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);
    }
}
philnash
  • 70,667
  • 10
  • 60
  • 88

1 Answers1

6

Apparantly by adding this line to code before sending request it fixed. To see more information go to related issue in this link:

Http Client for https endpoint

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Mehdi Mowlavi
  • 434
  • 1
  • 11
  • I have changed the framework to 4.5 and added the two lines code, ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; – Mohanven2003 May 27 '22 at 08:03