1

I'm working on an Angular application but when I call my local API I have this error

Failed to load https://localhost:44358/api/try: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

And I have also this :

ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …} error : ProgressEvent

So I saw some solutions and I try this on my .Net Core API in the startup file

        services.AddCors(options =>
        {
            options.AddPolicy("AnyOrigin", builder =>
            {
                builder
                   .AllowAnyOrigin()
                   .AllowAnyMethod()
                   .AllowAnyHeader()
                   .AllowCredentials();
            });
        });

But I have the same error ... Can I have some help ?

Finally it work, I think I forget to build my .Net Core API

  • I have detailed how to use the proxy server here: https://stackoverflow.com/questions/47345282/how-to-add-cors-request-in-header-in-angular-5/47933410#47933410 – rgantla Aug 01 '18 at 14:08
  • Thank it's help me but when I do this : ng serve --proxy-config proxy.conf.json I have an error in the command prompt : [HPM] Error occurred while trying to proxy request /api/Employee from localhost:4200 to https://localhost:44358 (UNABLE_TO_VERIFY_LEAF_SIGNATURE) (https://nodejs.org/api/errors.html#errors_common_system_errors) And on chrome I have this error : http://localhost:4200/api/Employee 500 (Internal Server Error) –  Aug 01 '18 at 14:29

1 Answers1

1

If you use Angular 6, Angular CLI supports Proxy Config which will proxy your backend API call. Please check the Docs. https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/proxy.md

Suresh Kumar Ariya
  • 9,516
  • 1
  • 18
  • 27