I know there already is a few questions on the topic, but I can't seem to find a solution to my problem.
I am fairly new to angular 4, and I am trying to build a simple create/update/delete service using an external custom API.
I first had issues with CORS, but that was fixed by setting the "Access-Control-Allow-Origin" header on the server side of the api.
Now my GET/PATCH and DELETE request work fine, but my "POST" still catches an error.
And here's the "odd" part.
When I check into the "network" tab of google chrome's developper tools, I see both "OPTIONS" and then "POST" request (as angular is supposed to do), but only the "OPTIONS" has "Access-Control-Allow-Origin:http://localhost:3003" in the response headers.
However they both send a "200" response code. (Here are some screenshots)
Why would the post break wheras the others work fine ?
Here are some code samples from my service :
private headers = new Headers({'Content-Type': 'application/json'});
// works
update(id: number, fields: any): Promise<Tag> {
const url = `${this.tagsUrl}/${id}`;
return this.http
.patch(url, JSON.stringify(fields), {headers: this.headers})
.toPromise()
.then(res => res.json())
.catch(this.handleError);
}
// doesn't work
create(tagName: string, tagType: number): Promise<any> {
return this.http
.post(this.tagsUrl, JSON.stringify({name: tagName, tagType: tagType}), {headers: this.headers})
.toPromise()
.then(res => res.json())
.catch(this.handleError);
}
Thanks in advance for any help you can bring !
Michael