When I call my webAPI controller, which contains the post method with NO parameters, it jumps to the method. However, when I pass the parameters (and when I update the api controller with the parameters), see the Snippet below the first snippet. I get a 405 error that does not support POST.
var captchURL = "/api/Captcha"; $.ajax({ url: captchURL, dataType: 'json', contentType: 'application/json', type: 'POST' }) var jsondata = {solution: "7", answer: "7"}; var captchURL = "/api/Captcha"; $.ajax({ url: captchURL, dataType: 'json', contentType: 'application/json', type: 'POST', data: JSON.stringify(jsondata) })
UPDATE - Controller code:
public class CaptchaController : ApiController { private readonly ICaptchaService _service; public CaptchaController(ICaptchaService service) { _service = service; } public Captcha Get() { return _service.Get(); } [HttpPost] public bool Post(string solution, string answer) { return _service.Post(); } }
UPDATE - WebApiConfig:
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } );
Is it because I do not have solution and response parameters (in my WebApiConfig), that it does not recognize them?
What am I doing wrong?
source share