abh
abh

Reputation: 141

Twilio SendSmsMessage with callbackURL not working?

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?

Edit: 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!

Upvotes: 0

Views: 534

Answers (1)

abh
abh

Reputation: 141

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.

Upvotes: 1

Related Questions