ทุกคนคงเคยเจอกับ error cors แต่โดยปกติ เราก็จะ allow * กัน 555
มันจะดีกว่าไหม ถ้าเรารู้จริงๆว่าโปรแกรมต้องการอะไร!!!
Access to XMLHttpRequest at ‘http://localhost:1323/api/users’ from origin ‘http://localhost:4200’ has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
หรือ
Access to XMLHttpRequest at ‘http://localhost:1323/api/users’ from origin ‘http://localhost:4200’ has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
![](https://kreangkrai.com/wp-content/uploads/2020/11/Selection_317.png)
นั้นหมายความว่า เราต้องเพิ่ม
echo.HeaderAuthorization
echo.HeaderContentType
![](https://kreangkrai.com/wp-content/uploads/2020/11/image-6.png)
![](https://kreangkrai.com/wp-content/uploads/2020/11/image-7.png)