I´m using inoic 4 and want to make a simple http get but I alwas get Access to XMLHttpRequest at ‘MY_API_LINK’ from origin ‘https://192.168.178.21:8100’ 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.
I´m using a Asp.Net Api with basic authentication. I also tried a Chrome plugin to disable cors.
I hope that someone can help me cause I´m really frustrated
thanks for your reply. I solved the problem by using the agnular HttpClient with the request method instead of httpClient.get. I´m not sure why it works now but thanks for your help.
No problem It could be also a solution for you. Do you maybe know how i can return the data after I made a subscribe ?
If I try to return this.user after the subscribe the user will be undefined.
Well, if you do a console.log(response) you’ll see the structure of the returned data and can apply the values to user.
Not sure why you have return this.user in there?
If you do need return this.user, it MUST be within the subscribe section of your code…
this.apiService.getUserByUsername(this.username)
.subscribe(response => {
this.user = response;
return this.user; // only return the value after it is returned by the service
});