TwilioClient.Init(accountSid, authToken); var restClient = TwilioClient.GetRestClient(); var message = restClient.SendMessage( from: "+14155551234", to: "+14155556789", body: "Hello from Twilio!"); Console.WriteLine(message.Sid);
var credentials = new NetworkCredential(accountSid, authToken); var restClient = new RestClient("https://api.twilio.com") { Authenticator = new HttpBasicAuthenticator(credentials.UserName, credentials.Password) }; var request = new RestRequest($"/2010-04-01/Accounts/{accountSid}/Messages.json", Method.POST); request.AddParameter("From", "+14155551234"); request.AddParameter("To", "+14155556789"); request.AddParameter("Body", "Hello from Twilio!"); var response = restClient.Execute(request); Console.WriteLine(response.Content);In this example, we manually create a RestClient object with a base URL of https://api.twilio.com. We also set the Authenticator property to use HTTP Basic authentication with our accountSid and authToken. Then we create a RestRequest object that specifies the URL path and HTTP method (POST). We use the AddParameter method to add the necessary parameters to send a SMS message. Finally, we execute the request and print the response content. The Twilio library for C# is available on NuGet under the package name "Twilio".