相关疑难解决方法(0)

从 Angular HttpClient 向 ASP.NET Core 2.2 Web API(启用 CORS)进行 POST 调用时出现 404 错误

我写了一个简单的ASP.NET Core 2.2 Web API. 该POST方法始终返回404,但 GET 请求成功。

public class TestPayload
{
    public string test1 { get; set; }
    public string test2 { get; set; }
}

[Route("api/[controller]")]
[ApiController]
public class TestController: ControllerBase
{        
    // POST api/create
    [HttpPost]
    public async Task<ActionResult<string>> Create([FromBody] TestPayload value)
    {
        return Ok("");
    }
}
Run Code Online (Sandbox Code Playgroud)

我在 Angular HttpClient 前端收到 404 错误。

let headers = new HttpHeaders().set('Content-Type', 'application/json');

return this.http.post<any>(`${config.apiUrl}/test/create`, { test1, test2}, { headers }).pipe(map(x => {
                        ...               
                        return x; …
Run Code Online (Sandbox Code Playgroud)

c# cors asp.net-core asp.net-core-webapi

0
推荐指数
1
解决办法
1566
查看次数

标签 统计

asp.net-core ×1

asp.net-core-webapi ×1

c# ×1

cors ×1