Issue
I'm getting error 415 on angular api request but http header are set:
login.service.ts:
var httpHeaders = new HttpHeaders();
httpHeaders.set('Content-Type', 'application/json');
httpHeaders.set('Access-Control-Allow-Origin', '*');
return this.httpClient.post<any>(requestUrl, params, { headers: httpHeaders })
As backend i used django rest framework Any idea ? Thans in advance.
Solution
HttpHeaders
class is immutable in Angular so now you did not really set any headers. You need to assign the result of set
operation to you variable.
let httpHeaders = new HttpHeaders();
httpHeaders = httpHeaders.set('Content-Type', 'application/json');
// depending on the server settings might also be needed
httpHeaders = httpHeaders.set('Accept', 'application/json');
httpHeaders = httpHeaders.set('Access-Control-Allow-Origin', '*');
return this.httpClient.post<any>(requestUrl, params, { headers: httpHeaders })
Answered By - Lukasz Gawrys
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.