Why is my ASP.NET Web API route working with Postman but not working with Angular Post request

前端 未结 2 1411
半阙折子戏
半阙折子戏 2021-01-20 23:13

I have no idea what\'s going on here. I have a POST route using ASP.NET web API that should change some data in my SQL Server. When I use Postman to test out my REST API it work

相关标签:
2条回答
  • 2021-01-20 23:36

    Postman does not send a XmlHttp Request. With postman you're manually interacting with a site so that you have full control. However in your web application you are making a Cross Origin Request.You need to enable CORS in your Api.
    You can read more about CORS in Asp.Net Web API here.

    0 讨论(0)
  • 2021-01-20 23:43

    In Global.asax.cs file add following code

    protected void Application_BeginRequest()
        {
            if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
            {
                Response.Flush();
            }
        }
    
    0 讨论(0)
提交回复
热议问题