The API is protected with a login. After I enter the login on the direct site, it shows curl result, which contains a token. At some point I was able get the result by doing:
const headers = new HttpHeaders() .set('accept', 'application/json') .set('Authorization', `Bearer xxxx<); //xxx is the token and
this.data = this.http.get(url, { headers: headers }) But it doesn't work anymore.
Also, I think I should be able able to do http.post with user credentials, get a token and get json from API using the token. I am kind of confused. I read a lot of SO posts, but neither were helpful in my case. I still get nothing.
Also, the token changes time after time. Could it be the reason?
This seems to work:
this.data = this.http.post(this.url, { headers: headers }) .subscribe((res) => { return res }) But this doesn't
this.data = this.http.post(this.url, { username: 'username', password: 'password' }) //with real credentials .subscribe((res) => { return res }) This request gives 405 error :(
this.http.post(this.url, { username: 'username', password: 'password' }) .subscribe((res) => { return res })