我需要测试 405 错误页面,但我不知道如何创建 405 错误。
有没有办法在我的网站上重现 405 错误?
最佳答案
HTTP 响应状态代码 405
表示 Method Not Allowed
。 此状态代码表明 HTTP 方法已被服务器接收并识别,但服务器拒绝了所请求资源的特定方法。
激发响应代码 405
的最简单方法是
- 尝试访问一个不存在的资源/URL
- 尝试在未经适当许可的情况下访问现有资源。
使用类似 Postman 的 HTTP 工具尝试以下示例
以下 HTTP 请求试图在没有正确许可的情况下在 /api/values/
上使用 PUT
方法
PUT /api/values/1 HTTP/1.1
Content-type: application/json
Host: localhost
Accept: */*
Content-Length: 12
"Some Value"
HTTP 响应状态代码 405
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Date: Wed, 15 May 2013 02:38:57 GMT
Content-Length: 72
{"Message":"The requested resource does not support http method 'PUT'."}
关于http - 如何创建 405 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52049389/