I am trying to fetch data from the udemy api, but get the following error:
Access to XMLHttpRequest at 'https://www.udemy.com/api-2.0/courses' 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.
data.service.ts
enter code here
import { Injectable } from '@angular/core';
import {HttpHeaders, HttpClient} from '@angular/common/http'
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class DataService {
headers ={
headers:new HttpHeaders({
Accept: "application/json, text/plain, */*",
Authorization:
"Basic xxx...x.xxxx",
"Content-Type": "application/json;charset=utf-8"
}).set( 'Access-Control-Allow-Origin', "*")
}
constructor(private http:HttpClient) { }
getCourses(){
return this.http
.get('https://www.udemy.com/api-2.0/courses', this.headers).pipe(
map(data => {
//return data;
console.log(data)
})
)
}
}
I have the access Authorization that am trying to pass in the header but still getting the error