This question already has an answer here:
- How does Access-Control-Allow-Origin header work? 13 answers
I'm making an app in angular 7 that connects to API that I wrote in python. I want to send a text in POST request and API does some nlp stuff and returns the result. API is using RestPlus and is hosted on GCP App Engine. So in angular I have this code:
posts: any;
readonly ROOT_URL = 'XXX';
const httpOptions = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
'X-API-KEY': 'X',
})
};
const data: any = {
"article": this.text
};
this.posts = this.http.post(this.ROOT_URL, data, httpOptions);
this.text is a value I get from form and I've already checked if it's valid. X-API-KEY is a token I set in API.
In console I get:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at XXX. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at XXX. (Reason: CORS request did not succeed).
I tried sending a post request to postb.in to test it and got the same errors. And postb.in shows that it only received OPTION requests.