![](/img/trans.png)
[英]Full VB.NET code using C# lib - Twilio example for SMS and MMS message
[英]twilio nuget package not sending SMS message in vb.net
twilio asp.net帮助程序库包在vb.net中不起作用吗? 我可以使它在c#Web应用程序中工作,但不能在vb.net Web应用程序中工作。
在vb.net Web应用程序项目中,以下代码不会发送短信,而在调试器中逐步执行时,发送消息行会出错,并显示一个文件对话框,要求访问core.cs。 twilio库是通过nuget安装的。
Public Shared Sub SendAuthCodeViaSms(ByVal number As String)
Dim twilioAccountInfo As Dictionary(Of String, String) = XmlParse.GetAccountInfoFromXmlFile("twilio")
Dim accountSid As String = twilioAccountInfo("username")
Dim authToken As String = twilioAccountInfo("password")
If (Not String.IsNullOrEmpty(accountSid) AndAlso Not String.IsNullOrEmpty(authToken)) Then
Dim client = New TwilioRestClient(accountSid, authToken)
client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
Else
'log error and alert developer
End If
End Sub
但是在C#Web API项目中,相同的代码按预期发送消息。
protected void Page_Load(object sender, EventArgs e)
{
const string AccountSid = "mysid";
const string AuthToken = "mytoken";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(TwilioSendNumber,ToNumber,"text message from twilio");
}
并且所有sid和令牌以及电话号码格式都是正确的,否则C#不会发送,而我也不会到达client.vb.net版本的sendMessage部分(client.SendSMSMessage会产生相同的结果)
Twilio的传播者在这里。
我通过创建一个简单的VB控制台应用程序尝试了您的代码,它对我有用。
我唯一能想到的是,解析XML时您没有正确获得Twilio凭据,或者传递给该函数的电话号码格式不正确。
我建议将对SendMessage()的调用结果放入变量中,并检查RestException属性是否为null:
Dim result = client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
If (Not IsNothing(result.RestException)) Then
' Something bad happened
Endif
如果Twilio返回的状态码大于400,则它将在RestException属性中显示为异常,并为您提供提示。
如果这不起作用,则始终可以使用Fiddler之类的工具进行监视,以查看该库是否发出了HTTP请求属性,而Twilio返回的是正确的结果。
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.