Axios having CORS issue

后端 未结 6 1944
温柔的废话
温柔的废话 2020-11-30 05:38

I added proxy in package.json and it worked great, but after npm run build the CORS issue has resurfaced again, does anyone know how to deal with CORS issue after npm run bu

6条回答
  •  天命终不由人
    2020-11-30 06:04

    This work out for me :

    in javascript :

    Axios({
                method: 'post',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                url: 'https://localhost:44346/Order/Order/GiveOrder',
                data: order
              }).then(function (response) {
                console.log(response.data);
              });
    

    and in the backend (.net core) : in startup:

     #region Allow-Orgin
                services.AddCors(c =>
                {
                    c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
                });
                #endregion
    

    and in controller before action

    [EnableCors("AllowOrigin")]
    

提交回复
热议问题