404 error when making a POST call from Angular HttpClient to ASP.NET Core 2.2 Web API (with CORS enabled)

蓝咒 提交于 2019-12-02 08:14:32

You have not specified a route to the action. You can either change your post to go to /api/Test or set the attributes on the action as follows:

[HttpPost("Create")]
public async Task<ActionResult<string>> Create([FromBody] TestPayload value)
{
    return Ok("");
}

or

[HttpPost]
[Route("Create")]
public async Task<ActionResult<string>> Create([FromBody] TestPayload value)
{
    return Ok("");
}

or update the controller route to include the action

[Route("api/[controller]/[action]")]
Harald Pollak

Try to add:

[EnableCors(origins: " * ", headers: " * ", methods: " * ")]

to your Controller class. ( remove with spaces in the quotes )

More info on Microsoft-Website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!