When I send request to my API Gateway with Angular I have this error :
*Access to XMLHttpRequest at 'https://example.com' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.*
And if I add 'Access-Control-Allow-Origin':'*' I have this one :
*Access to XMLHttpRequest at 'https://example.com' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.*
But the same request works perfectly with CURL, web browser and another mobile app (Flutter).
I tried to enable (with Access-Control-Allow-Origin:'*') and disable CORS in API Gateway but the problem remains the same.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class mainService {
constructor(private http: HttpClient) {}
getAll() {
return this.http.get<any>("https://example.com",
{
headers: HttpHeaders({'Access-Control-Allow-Origin':'*'})
});
}
}