简体   繁体   English

使用C#的Twilio SMS沙箱

[英]Twilio SMS sandbox using C#

How do you use the Twilio sandbox mode with C#? 您如何在C#中使用Twilio沙箱模式? I have a ashx.cs file that I am using to write my code. 我有一个用于编写代码的ashx.cs文件。 Would I put it there? 我可以把它放在那里吗? If so, what does that look like? 如果是这样,那看起来像什么?
There is no real great examples on their website on how to do this except for CURL and Ruby. 除了CURL和Ruby,在他们的网站上没有真正的好例子。

We are using TwiML to general an XML file tha t parses our data to send back and forth to the Twilio service. 我们正在使用TwiML通用XML文件,该XML文件解析我们的数据以将其来回发送到Twilio服务。 We don't want to be charged every time we send a test text message. 我们不想每次发送测试短信时都要收费。 How would we set the Sandbox up so we could do some testing. 我们将如何设置沙盒,以便进行一些测试。
I found the Test auth Token and account Sid, but how do I use those? 我找到了测试身份验证令牌和帐户Sid,但是如何使用它们呢? We don't have them in our current application and we are specifying our .ashx page in Twilio to process our code. 我们当前的应用程序中没有它们,我们在Twilio中指定.ashx页面来处理代码。

Thanks in advance. 提前致谢。

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

So if you just want to test that your ASHX handler is generating the right results the easiest way to do this is to just fake a POST or a GET request to that handler. 因此,如果您只想测试ASHX处理程序是否生成正确的结果,最简单的方法就是伪造对该处理程序的POST或GET请求。 This lets you simulate the GET or POST request that Twilio will make to your app when it gets a text message. 这使您可以模拟Twilio在收到文本消息时将向您的应用程序发出的GET或POST请求。

You can see the parameters that Twilio will pass to your app when it receives a text message here: 您可以在此处查看Twilio收到文本消息时将传递给您的应用程序的参数:

http://www.twilio.com/docs/api/twiml/sms/twilio_request#synchronous http://www.twilio.com/docs/api/twiml/sms/twilio_request#synchronous

There are a whole bunch of ways to simulate these requests. 有很多方法可以模拟这些请求。 cURL is one of them. cURL是其中之一。 If your ASHX is expecting query string values, you can also just load the ASHX directly in the browser and append those values in the URL. 如果ASHX需要查询字符串值,则也可以直接在浏览器中直接加载ASHX,并将这些值附加在URL中。 If the handler is expecting a POST request, I used a chrome plugin called Simple REST Client to make these. 如果处理程序期望POST请求,那么我使用了一个名为Simple REST Client的chrome插件来制作这些插件。

Of course you can also Fiddler to make just about any HTTP request. 当然,您也可以让Fiddler发出几乎任何HTTP请求。

The Test Credentials really are more for simulating the use of the REST API (programatically sending SMS messages). 测试证书确实更多地用于模拟REST API的使用(以编程方式发送SMS消息)。 I just wrote a blog post that shows how to use the test credentials to create integration tests: 我刚刚写了一篇博客文章,展示了如何使用测试凭据来创建集成测试:

http://www.twilio.com/blog/2013/05/automating-twilio-integration-tests-with-test-credentials.html http://www.twilio.com/blog/2013/05/automating-twilio-integration-tests-with-test-credentials.html

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

Devin 德文

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

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