且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

请求的资源不支持 HTTP 方法“GET"

更新时间:2021-06-29 00:20:46

请在您的 WebAPI 操作中使用 System.Web.Http 命名空间中的属性:

Please use the attributes from the System.Web.Http namespace on your WebAPI actions:

    [System.Web.Http.AcceptVerbs("GET", "POST")]
    [System.Web.Http.HttpGet]
    public string Auth(string username, string password)
    {...}

它不起作用的原因是因为您使用了来自 MVC 命名空间 System.Web.Mvc 的属性.System.Web.Http 命名空间中的类用于 WebAPI.

The reason why it doesn't work is because you were using the attributes that are from the MVC namespace System.Web.Mvc. The classes in the System.Web.Http namespace are for WebAPI.