0

I want to access an api's data of this url : 'http://apis.coursefrenzy.com/courses/' i also have declared the all modules properly...

i tried to access with 'get()' method of 'HttpClient' class i.e. get(this.api, {headers: apiheader})

const httpOptions = {
      headers: new HttpHeaders({
          'Content-type': 'application/json',
          'Autorization': 'EpCuVuAOPGfoXNyXtDxDxNIozMxQ
                           7TC9W9C9FBlZsgUExQLH2zNOmFmWKnMBKKPE'
      })
};
api="http://apis.coursefrenzy.com/courses/";
getUser(){
    return this.http.get(this.api, {headers: httpOptions.headers});
}

when i subscribe to this get methode and cosole the data, then i have recieved and error in console...

Access to XMLHttpRequest at 'http://apis.coursefrenzy.com/courses/' from origin 'http://localhost:6565' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.enter image description here

  • 1
    enable CORS in the backend ! what platform are you using to write your api ... ? – AbolfazlR Oct 20 '19 at 11:45
  • this is a duplicate of https://stackoverflow.com/q/58361700/4604645; Please follow the answers there and that will get you going – The Fabio Oct 20 '19 at 11:58
  • Possible duplicate of [HttpClient.get for reading a file](https://stackoverflow.com/questions/58361700/httpclient-get-for-reading-a-file) – The Fabio Oct 20 '19 at 11:59
  • Hi, please check here, question has already been answered. (https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check) – Michael Ashefor Oct 20 '19 at 11:59

1 Answers1

0

You must set CORS origin parameter in your api , for example in .net core startup:

builder.WithOrigins("http://localhost:4200")