简体   繁体   English

WEB API错误404-“消息”:“请求的资源不支持http方法'PUT'。”

[英]WEB API error-404 - “Message”: “The requested resource does not support http method 'PUT'.”

HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET,POST
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcUHJvamVjdHNcZG90TmV0XFdlYkFQSVxBZFNlcnZpY2VcQWRTZXJ2aWNlXGFwaVxpbXByZXNzaW9uXDE1?=
X-Powered-By: ASP.NET
Date: Tue, 06 May 2014 14:10:35 GMT
Content-Length: 72

{"message":"The requested resource does not support http method 'PUT'."}

I want to generate PUT and DELETE request using POSTMAN but I got following message from POSTMAN. 我想使用POSTMAN生成PUT和DELETE请求,但是我收到了POSTMAN的以下消息。

Even I have implemented all the suggestions given by ASP.NET site. 甚至我都实现了ASP.NET网站给出的所有建议。

Below is Web API c# code: 以下是Web API c#代码:

 // PUT: api/Students/5
    [HttpPut]
    [ResponseType(typeof(void))]
    public IHttpActionResult PutStudent(decimal Enrollment_no, Student student)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        if (Enrollment_no != student.Enrollment_no)
        {
            return BadRequest();
        }

        db.Entry(student).State = EntityState.Modified;

        try
        {
            db.SaveChanges();
        }
        catch (DbUpdateConcurrencyException)
        {
            if (!StudentExists(Enrollment_no))
            {
                return NotFound();
            }
            else
            {
                throw;
            }
        }

        return StatusCode(HttpStatusCode.NoContent);
    }

Nothing has worked as I'm still getting a 405 response when trying to issue a "PUT" command against my Web API project. 没有任何反应,因为尝试对Web API项目发出“ PUT”命令时仍收到405响应。

您的后端api仅允许GET和POST请求(请参阅响应标头Allow),因此要生成PUT / DELETE请求API,应添加对它的支持。

You can configure this by modifying web.config of your ASP.NET Web API. 您可以通过修改ASP.NET Web API的web.config进行配置。 Try to find the following line: 尝试找到以下行:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

Replace it with: 替换为:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

Please refer here for more information. 请参阅此处以获取更多信息。

暂无
暂无

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

相关问题 Web API - 405 - 请求的资源不支持http方法&#39;PUT&#39; - Web API - 405 - The requested resource does not support http method 'PUT' ASP.NET Web API:“消息”:“请求的资源不支持 http 方法 &#39;POST&#39;、PUT、DELETE。” 在邮递员 - ASP.NET Web API: "Message": "The requested resource does not support http method 'POST', PUT, DELETE." in Postman “消息”:“请求的资源不支持http方法&#39;PUT&#39;。” - “Message”: “The requested resource does not support http method 'PUT'.” “请求的资源不支持HTTP方法&#39;PUT&#39;ASP.Net Web API - "The requested resource does not support HTTP method 'PUT' ASP.Net Web API ASP.NET Web Api“请求的资源不支持http方法PUT / DELETE” - ASP.NET Web Api “The requested resource does not support http method PUT/DELETE” 请求的资源不支持http方法“ PUT” - The requested resource does not support http method 'PUT' MVC和Web Api:请求的资源不支持http方法“ POST” - MVC and Web Api: The requested resource does not support http method 'POST' “消息”:“请求的资源不支持http方法&#39;POST&#39;。” .net api中的JSON返回 - “Message”: “The requested resource does not support http method 'POST'.” JSON return in .net api Asp.net Web api请求的资源不支持http方法&#39;GET&#39; - Asp.net Web api The requested resource does not support http method 'GET' ASP.NET Web API - 请求的资源不支持 Z80791B3AE7002CB88C246876D9FA 方法 - ASP.NET Web API - The requested resource does not support http method 'GET'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM