简体   繁体   English

twilio nuget软件包未在vb.net中发送SMS消息

[英]twilio nuget package not sending SMS message in vb.net

Does the twilio asp.net helper library package NOT work in vb.net? twilio asp.net帮助程序库包在vb.net中不起作用吗? I can get it to work in c# web app but not vb.net web app. 我可以使它在c#Web应用程序中工作,但不能在vb.net Web应用程序中工作。

In a vb.net web application project the following code doesnt send an sms message and when stepping through with the debugger, errs on the send message line and brings up a file dialog asking for access to core.cs. 在vb.net Web应用程序项目中,以下代码不会发送短信,而在调试器中逐步执行时,发送消息行会出错,并显示一个文件对话框,要求访问core.cs。 The twilio library's were installed via nuget. 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

But in a C# web API project the same code sends the message as expected. 但是在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");
    }

and all the sid's and tokens and phone number formats are correct, otherwise the c# one wouldnt send and I wouldnt get to the client.SendMessage part of vb.net version (client.SendSMSMessage produces the same result) 并且所有sid和令牌以及电话号码格式都是正确的,否则C#不会发送,而我也不会到达client.vb.net版本的sendMessage部分(client.SendSMSMessage会产生相同的结果)

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

I tried our your code by creating a simple VB console app and it worked for me. 我通过创建一个简单的VB控制台应用程序尝试了您的代码,它对我有用。

The only thing I can think of is that either you are not getting your Twilio credentials correctly when parsing the XML, or the phone number you are passing into the function is not formatted correctly. 我唯一能想到的是,解析XML时您没有正确获得Twilio凭据,或者传递给该函数的电话号码格式不正确。

I'd suggest putting the result of call to SendMessage() into a variable and checking to see if RestException property is null: 我建议将对SendMessage()的调用结果放入变量中,并检查RestException属性是否为null:

Dim result = client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
If (Not IsNothing(result.RestException)) Then
   ' Something bad happened
Endif

If Twilio returns a status code greater than 400, then that will show up as an exception in the RestException property and will give you a clue as to whats going on. 如果Twilio返回的状态码大于400,则它将在RestException属性中显示为异常,并为您提供提示。

If that does not work, you can always break out a tool like Fiddler to watch and see if the library is making the property HTTP request and Twilio is returning the proper result. 如果这不起作用,则始终可以使用Fiddler之类的工具进行监视,以查看该库是否发出了HTTP请求属性,而Twilio返回的是正确的结果。

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

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

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