팡이네

Angular에서 localhost Web API를 호출할 때 아래와 같은 오류가 발생할 경우


http failure response for (unknown url) 0 unknown error


You’ve run afoul of the Same Origin Policy – it says that every AJAX request must match the exact hostprotocol, and port of your site. Things that might cause this:

서버측에 CORS(Cross-Orgion Resource Sharing) Header를 추가해준다.

그 외 방법은 아래 링크를 참조한다.

https://daveceddia.com/access-control-allow-origin-cors-errors-in-angular/

https://stackoverflow.com/questions/29024313/asp-net-webapi2-enable-cors-not-working-with-aspnet-webapi-cors-5-2-3


I just added custom headers to the Web.config and it worked like a charm.

On configuration - system.webServer:

<httpProtocol>   <customHeaders>     <add name="Access-Control-Allow-Origin" value="*" />     <add name="Access-Control-Allow-Headers" value="Content-Type" />   </customHeaders> </httpProtocol>