简体   繁体   English

Twilio使用HttpClient发布短信

[英]Twilio post sms using HttpClient

I'm trying to post data to the Twilio Rest API to trigger a sms sendout. 我正在尝试将数据发布到Twilio Rest API以触发短信发送。

I've tryed to do what is instructed to do with cURL but with HTTP Post insted. 我已经尝试按照cURL的指示执行操作,但是要使用HTTP Post插入。

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. 我一直在获取StatusCode: 401, ReasonPhrase: 'UNAUTHORIZED' What am I missing here? 我在这里想念什么?

Twilio evangelist here. Twilio的传播者在这里。

Instead of including your credentials in the URL you should set them using the DefaultRequestHeaders property: 不应在URL中包含凭据,而应使用DefaultRequestHeaders属性进行设置:

var byteArray = Encoding.ASCII.GetBytes("username:password1234");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM