[英]Put, Delete Method is not wokring. error : HTTP/1.1 405 Method Not Allowed
Get、Post 方法正在运行,但我要运行 Put 和 Delete 请求,然后我会遇到错误消息。
完整的项目网址: https : //github.com/Dushyantsingh-ds/dotnet-issues/blob/main/Projects/EmployeeService/Readme.md
您的删除端点还应该有一个[Route(...)]
数据注释:
[Route("api/employee/{EmpId}")]
您必须决定要使用什么 - 配置文件中的属性路由或默认路由。
目前最常用的 API 使用方式是为控制器分配属性路由
[Route("~/api/[controller]/[action]]
public class EmployeeController : ApiController
你可以使用 https//localhost:44350/api/employee/get 来获取 Get()
等等
// /api/employee/get
public IEnumerable<Employee> Get()
// /api/employee/get/5
[HttpGet("{empId}")]
public HttpResponseMessage Get(int empId)
// /api/employee/post" for
public HttpResponseMessage Post([FromBody] Employee employee)
// /api/employee/delete/5
[Route("{empId}")]
public HttpResponseMessage Delete(int empId)
// /api/employee/put/5
[Route("{empId}")]
public HttpResponseMessage Put(int empId, [FromBody] Employee employee)
并且由于您没有将方法作为操作属性,因此您不需要使用 delete 和 put,您可以使用 get 和 post 代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.