相关疑难解决方法(0)

ASP.NET Web Api:请求的资源不支持http方法'GET'

我在ApiController上有以下动作:

public string Something()
{
    return "value";
}
Run Code Online (Sandbox Code Playgroud)

我已按如下方式配置了我的路线:

routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)

在测试版中,这工作得很好,但我刚刚更新到最新的Release Candidate,现在我看到这样的调用出错了:

请求的资源不支持http方法'GET'.

为什么这不再工作了?

(我想我可以摆脱{action}而只是制造大量的控制器,但这感觉很麻烦.)

asp.net asp.net-web-api

90
推荐指数
7
解决办法
14万
查看次数

Web api不支持POST方法

在我的web api控制器中,我有一个带有以下代码的功能

       [HttpPost]
        public HttpResponseMessage Post(string schooltypeName)
        {
            _schoolTypeService.RegisterSchoolType(schooltypeName);

            var message = Request.CreateResponse(HttpStatusCode.Created);

            return message;
        }
Run Code Online (Sandbox Code Playgroud)

当我与小提琴手打电话时,我收到了这个错误

{"Message":"The requested resource does not support http method 'POST'."}
Run Code Online (Sandbox Code Playgroud)

我的摆弄参数是

User-Agent: Fiddler

Host: myhost:8823

Content-Type: application/json; charset=utf-8

Content-Length: 26
Run Code Online (Sandbox Code Playgroud)

请求正文

{"schooltypeName":"Aided"}
Run Code Online (Sandbox Code Playgroud)

请求网址是

http://myhost:8823/SchoolType
Run Code Online (Sandbox Code Playgroud)

(我配置了网址,GET正在使用此网址)

这里有什么不对?

c# asp.net asp.net-mvc asp.net-web-api

31
推荐指数
4
解决办法
6万
查看次数

标签 统计

asp.net ×2

asp.net-web-api ×2

asp.net-mvc ×1

c# ×1