5

I have a C# / .NET WebApi endpoint tied to a number. When that number receives a text, it's forwarded to my API via webhook.

Sometimes (not all the time), I get an error in my debugger with the following:

Error - 12300

Invalid Content-Type

Twilio is unable to process the Content-Type of the provided URL. Please see the Twilio Markup XML Documentation for more information on valid Content-Types. You must return a Content-Type for all requests. Requests without a Content-Type will appear in the App Monitor as a 502 Bad Gateway error.

In the response that triggered this, I see the following:

enter image description here

With the following headers:

Content-Type application/json; charset=utf-8 
Pragma no-cache 
Date Sat, 14 Jan 2017 02:57:45 GMT 
X-AspNet-Version 4.0.30319 
X-Powered-By ASP.NET

What might be causing this, and how do I address it?

SB2055
  • 12,272
  • 32
  • 97
  • 202

2 Answers2

7

After some research from TWIML MESSAGE: YOUR RESPONSE this code seems to work

[HttpGet]
public HttpResponseMessage SmsAnswerCallBack(string id)
{
    _smsAnswerCallBackCallIndex++;
    var r = new SmsApiResult();

    r.SetStatus(true, _smsSendCallIndex, _smsAnswerCallBackCallIndex);
    r.DataList  = _answers;

    var res     = Request.CreateResponse(HttpStatusCode.OK);
    res.Content = new StringContent("<Response/>", Encoding.UTF8, "text/xml");
    return res;
}
Frederic Torres
  • 682
  • 7
  • 14
  • I was about to pull every last stand of hair out. Thanks for this. – user1447679 Oct 27 '17 at 21:27
  • Perfect, looks like Twilio is looking for XML in TwiML format. I too was sending a json response. But if you basically just return in text/xml format, that satisfies Twilio. – lucky.expert Jun 16 '21 at 20:09
2

I too was sending a json response and getting this error. Using the answer by Frederic Torres got me on the right track. It looks like Twilio is looking for XML in TwiML format. But if you basically just return an empty "Response" element in text/xml format, that satisfies Twilio. So here is a simplified answer for anybody else that runs into this:

    public ContentResult IncomingSMS(string To, string From, string Body)
    {
            //do stuff
            //...
            return Content("<Response/>", "text/xml");
    }
lucky.expert
  • 743
  • 1
  • 15
  • 24