I'm trying to post data to the Twilio Rest API to trigger a sms sendout.
I've tryed to do what is instructed to do with cURL but with HTTP Post insted.
https://AccountSID:AuthToken@api.twilio.com/2010-04-01/Accounts/AccountSID/Messages
Then in the body I post data looking like this:
public class TwilioMessage
{
public string To { get; set; }
public string From { get; set; }
public string Body { get; set; }
}
I'm getting StatusCode: 401, ReasonPhrase: 'UNAUTHORIZED'
all the time. What am I missing here?
Twilio evangelist here.
Instead of including your credentials in the URL you should set them using the DefaultRequestHeaders property:
var byteArray = Encoding.ASCII.GetBytes("username:password1234");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
Hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.