如何将内容类型添加到Twilio响应?

时间:2013-08-11 15:13:21

标签: twilio asp.net-web-api

如何向Twilio Response添加内容类型?我收到502错误的网关错误,错误说它可能是因为缺少Content-Type。但我确实看到响应具有Content-type。那可能会出现什么问题?我也看到twilio的原因是连接超时!那是什么意思?这与我之前发表的帖子有关:An attempt to retrieve content from returned the HTTP status code 502. Please check the URL and try again

 Response - The HTTP headers and body of your server's response to Twilio

 Headers

 Content-Type   text/html
 Transfer-Encoding  chunked
 X-Twilio-Reason    connection timed out
 Body

 1
 <html><head><title>502 Bad Gateway</title></head><body><h1>Bad Gateway</h1>An upstream server returned an invalid response.</body></html>

有人可以帮助我找出twilio在访问我的API时出错的原因吗? 这就是我在我的控制器中所拥有的:

      public class TestController : ApiController
{      
    [HttpPost]
    public HttpResponseMessage  Post([FromBody]SmsRequest smsReq)
    {

        string smsReqUpper = smsReq.Body.ToUpper();
        string testString = "TEST";
        var response = new Twilio.TwiML.TwilioResponse();

        if (smsReqUpper == testString)
        {                               
            response.Sms("Test Successful");
            return Request.CreateResponse(HttpStatusCode.OK, response.Element);

        }
        else
        {
            string strBody = "Invalid Text Command. Please text the word TEST " ;
            response.Sms(strBody);
            return Request.CreateResponse(HttpStatusCode.OK, response.Element);

            //return new TwiMLResult(response);
        } 
    }

1 个答案:

答案 0 :(得分:1)

Content-Type text/html位是指502错误的网关响应,而不是来自服务器的实际响应。将“text / xml”内容类型添加到您的请求中(我不认识您正在使用的框架),您应该很高兴。

要调试您的回复,您可以使用curl -vvv [URL],直到Content-Type: text/xml部分出现。