简体   繁体   English

405不允许调用WebAPI的方法

[英]405 Method not allowed in calling to WebAPI

I am calling using following request to a web service (copypaste from Chrome dev panel): 我正在使用对Web服务的以下请求进行调用(来自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"

to a webservice method that has such a signatue: 具有以下特征的webservice方法:

   [HttpPost]
    public replyObj setCurrentProject(string userName, int projectId)
    {
    /// ... 
    }

as you see I followed interface in every detail. 如您所见,我在每个细节上都遵循界面。 If I change method to PUT, other method is called with [HttpPut] attribute even if sugnature does not match, and this config just gives me {"Message":"The requested resource does not support http method 'POST'."} contrary to what I declared. 如果我将方法更改为PUT,则即使sugnature不匹配,也会使用[HttpPut]属性调用其他方法,并且此配置仅给我{“ Message”:“”所请求的资源不支持http方法'POST'。“}相反达到我的声明。

Recently I've faced with the same problem. 最近,我遇到了同样的问题。 It seems that your method signature doesn't match the route. 您的方法签名似乎与路由不匹配。 Change your method to 将方法更改为

public replyObj setCurrentProject(dynamic value)
{
/// ... 
}

or you can use your appropriate class instead dynamic 或者您可以使用适当的类而不是dynamic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM