I am trying to send SMS message from c# unit test code but I am not able to receive the text message and I don't know where to debug this.
Also, inside my response object, I get the value "Bad Request". What am I doing wrong. Also in while loop, I wait for the response to get processed.
Here is my code.
[TestMethod]
public void TestMethod1()
{
Assert.IsTrue(SendMessage("+1MYFROMPHONENUMBER", "+1MYTOPHONENUMBER", "sending from code"));
}
public bool SendMessage(string from, string to, string message)
{
var accountSid = "MYACCOUNTSIDFROMTWILIOACCOUNT";
var authToken = "MYAUTHTOKENFROMTWILIOACCOUNT";
var targeturi = "https://api.twilio.com/2010-04-01/Accounts/{0}/SMS/Messages";
var client = new System.Net.Http.HttpClient();
client.DefaultRequestHeaders.Authorization = CreateAuthenticationHeader("Basic", accountSid, authToken);
var content = new StringContent(string.Format("From={0}&To={1}&Body={2}", from, to, message));
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
var result = false;
var response = client.PostAsync(string.Format(targeturi, accountSid), content).Result;
do
{
result = response.IsSuccessStatusCode;
} while (result == false);
return result;
}