带有 callbackURL 的 Twilio SendSmsMessage 不起作用? [英] Twilio SendSmsMessage with callbackURL not working?

查看:38
本文介绍了带有 callbackURL 的 Twilio SendSmsMessage 不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 C# 与 RestSharp 版本 105.0.1 和 Twilio 版本 3.6.27 一起使用.我设置了一个 HTTP 侦听器,它可以使用 GET 或 POST 配置将传入消息发送到我的 twilio 电话号码.当我使用 SendSmsMessage 方法并将 statusCallback 设置为 Twilio 配置中用于传入 SMS 消息的相同 URL 时,我没有收到任何发布到该 URL 的信息.消息发出很好,我在返回的消息对象中取回了 sid,并且可以检查它的状态.

I’m using C# with the RestSharp version 105.0.1 and Twilio version 3.6.27. I have an HTTP listener set up, and it works with either GET or POST configurations for incoming messages to my twilio phone number. When I use the SendSmsMessage method with the statusCallback set to the same URL that’s in the Twilio configuration for incoming SMS messages, I don’t get anything POSTed to that URL. The message goes out fine, I get the sid back in the returned message object, and can check it’s status.

有人做过这个吗?如果是这样,你能提供任何想法来帮助我调试这个问题吗?

Has anyone made this work? If so, can you offer any ideas to help me debug this problem?

我花了一些时间来缩小范围.我的 httpListener 使用来自 http://blog.mikehacker.net/的代码2006/11/13/httplistener-and-forms/ 解析出POST数据.它检查 httpListenerRequest.HasEntityBody,并且仅在为真时才尝试解析数据.事实上,当我向我的 twilio 号码发送消息时,POST 消息将 HasEntityBody 设置为 true,并且数据被正确解析.当我从 RestAPI 发送消息 OUT 并指定回调 URL 时,POST 消息不会将 HasEntityBody 设置为 true,因此永远不会尝试解析.即使我忽略了 HasEntityBody 的状态,StreamReader 似乎也没有获取任何数据,即使我在 wireshark 捕获中看到了它.

I spent some time narrowing this down a bit. My httpListener uses the code from http://blog.mikehacker.net/2006/11/13/httplistener-and-forms/ to parse out the POST data. It inspects the httpListenerRequest.HasEntityBody, and only attempts to parse the data if that’s true. In fact, when I send a message TO my twilio number, the POST message sets HasEntityBody true, and the data gets parsed out correctly. When I send a message OUT from the RestAPI, and specifcy a callback URL, the POST messages do not set HasEntityBody true, so the parsing is never attempted. Even if I ignore the state of HasEntityBody, it doesn’t seem as if the StreamReader is getting any data, even though I see it in the wireshark capture.

任何进一步的想法/见解将不胜感激!

Any further thoughts / insights would be greatly appreciated!

推荐答案

问题已解决,回调 URL 可以正常工作.上面引用的 Mike Hacker 博客文章中的代码假定内容类型为application/x-www-form-urlencoded",并且当 Twilio POST 是一条传入的 SMS 消息,即它发送的内容,因此代码有效.当 Twilio 发布到回调 URL 时,它将内容类型字符串发送为application/x-www-form-urlencoded;charset=utf-8",这打破了解析逻辑.简单的解决方法是将相等性测试更改为包含".我之前对 HasEntityBody 的评论是我的调试错误,抱歉.

Problem has been resolved, and the callback URL works as advertised. The code from the Mike Hacker blog post referenced above assumes the content type will be "application/x-www-form-urlencoded", and when Twilio POSTs an incoming SMS message, that what it sends, so the code works. When Twilio posts to the callback URL, it sends the content type string as "application/x-www-form-urlencoded; charset=utf-8", which breaks the parsing logic. The simple fix is to change the test for equality to a "contains". My earlier comment about HasEntityBody was a debugging error on my part, sorry.

这篇关于带有 callbackURL 的 Twilio SendSmsMessage 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆