Reputation: 529
What am I doing wrong in this code? When I send a POST request to this API i get the 404 error page. Can somebody help me debug this code. New to Rest Api and Twilio.
using System.Web.Mvc;
using Twilio.TwiML.Mvc;
using Twilio.Mvc;
namespace MVC4Test.Controllers
{
public class HomeController : TwilioController
{
[HttpPost]
public TwiMLResult ActionResult(SmsRequest request)
{
string smsTextType = request.Body;
var response = new Twilio.TwiML.TwilioResponse();
Response.ContentType = "text/xml";
response.Redirect("http://www.google.com");
//Response.ContentEncoding = System.Text.Encoding.UTF8;
//Response.Write(smsTest);
return TwiML(response);
//Response.Close();
}
}
}
This is my route
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Upvotes: 1
Views: 631
Reputation: 10366
Twilio evangelist here.
Can you post the URL your are trying to load?
My first guess is that you mistakenly named your Action method. Right now its this:
public TwiMLResult ActionResult(SmsRequest request)
That would mean the URL you need to request is:
http://[yourdomain]/Home/ActionResult
If you change the name of the method:
public ActionResult Sms(SmsRequest request)
Then your URL would be:
http://[yourdomain]/Home/Sms
A couple of other things I noticed:
<Redirect>
Hope that helps.
Upvotes: 1