I'v been trying to access various apis through SPFx and I am constantly seeing this issue. I do not know how to fix this can anyone assist or explain what I am doing wrong or missing?
This works perfectly fine with $.getJSON("https://www.mindicador.cl/api").then(console.log)
workbench.html:1 Access to fetch at 'https://www.mindicador.cl/api' from origin 'https://localhost:4321' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
My function:
private makeRequest(): Promise<HttpClientResponse> {
const url = `https://www.mindicador.cl/api`;
const requestHeaders: Headers = new Headers();
requestHeaders.append("Content-type", "application/json");
requestHeaders.append("Accept", "application/json");
requestHeaders.append("Access-Control-Allow-Origin", "*");
const httpClientOptions: IHttpClientOptions = {
headers: requestHeaders,
method: "GET"
};
return this.context.httpClient
.get(url, HttpClient.configurations.v1, httpClientOptions)
.then(response => {
console.log(response);
return response.json();
});
}