![](/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.