【发布时间】:2014-05-21 08:09:04
【问题描述】:
我正在使用以下请求调用网络服务(从 Chrome 开发面板复制粘贴):
Request URL:https://localhost:44300/api/userpreferences
Request Method:POST
Status Code:405 Method Not Allowed
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:51
Content-Type:application/json;charset=UTF-8
Host:localhost:44300
Origin:http://localhost:3000
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
Request Payloadview source
{userName:asasa, projectId:2}
projectId: 2
userName: "asasas"
到具有这种签名的网络服务方法:
[HttpPost]
public replyObj setCurrentProject(string userName, int projectId)
{
/// ...
}
如您所见,我在每个细节上都遵循了界面。如果我将方法更改为 PUT,即使 sugnature 不匹配,也会使用 [HttpPut] 属性调用其他方法,并且此配置只给我 {"Message":"The requested resource does not support http method 'POST'."} 与我声明的相反。
【问题讨论】:
-
这可能会有所帮助:blog.dontpaniclabs.com/post/2013/01/23/… ..........System.Web.Http" 和 "System.Web.Mvc" 有一个 "[HttpPost]" 属性使用 " [System.Web.Http.HttpPost]" 属性
-
你能显示你的路线吗?
标签: c# asp.net web-applications asp.net-web-api