Why get request works fine in Postman but not locally?
Postman gives me proper response, but when in browser I get 401 Unauthorized. Why?
This is my Service
getDepartments(id): Observable<any>{
return this.http.get(this.baseurl + '/api/v1/universities/' + id + '/departments/', {headers:
this.httpHeaders} )
}
This is my component.ts
getAllDepartments = () =>{
this.api.getDepartments(this.token.university).subscribe(
data =>{
this.departments = data;
},
error => {
console.log(error);
}
)
}
These are how I create my headers:
httpHeaders = new HttpHeaders({'Content-Type':'application/json'});
That’s what I get:
Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7
Authorization: Bearer 4fa4071036d107c482d2f768921518034cb9ae13
Connection: keep-alive
Content-Type: application/json
Host: signmeupapi.herokuapp.com
Origin: http://localhost:4200
Referer: http://localhost:4200/admin
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 OPR/73.0.3856.284
(Edition Campaign 76)
Link is fine, I have the same token in headers and I’m totally lost. On the server side cors headers work fine, I was able to log in and get token, but here nothing seems to work.
Source: Angular Questions