Ajax Post: 405 Method Not Allowed

后端 未结 3 1517
庸人自扰
庸人自扰 2021-02-07 09:19

Within my API Controller called Payment, I have the following method:

[HttpPost]
public HttpResponseMessage Charge(Payment         


        
相关标签:
3条回答
  • 2021-02-07 09:55

    Turns out I needed to implement CORS support. http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/20/implementing-cors-support-in-asp-net-web-apis.aspx

    0 讨论(0)
  • 2021-02-07 10:14

    Most likely your routing is not configured for the action to be invoked. Hence the request ends up in nowhere and ASP.NET Web API sends a blank-out message "method not allowed".

    Can you please update the question with your routing?


    UPDATE

    As I thought! You are sending to http://localhost:65396/api/payment/charge while you need to send to http://localhost:65396/api/payment - assuming your controller is called PaymentController.

    Note that route does not have action.

    0 讨论(0)
  • 2021-02-07 10:16

    I had the same problem with my controller. The only thing which is different is the ending of the URL. Add "/" to "http://localhost:65396/api/payment/charge" at the end, that helped me

    0 讨论(0)
提交回复
热议问题