Hello,
I am trying to send the GET request to ovirt server but gets error 401 (Unauthorized).
Here is some more detailed background.
First I send the POST request to the server to get the authentication token, this goes successful and I get the auth token.
Then I am trying to send the GET request with authentication token in the header as below.
getdata() {
this.token = 'xxxxxxxxxx';
let headers = new HttpHeaders();
headers = headers.append("Content-Type", "application/x-www-form-urlencoded");
headers = headers.append("Accept", "application/json");
headers = headers.append("Authorization", "Bearer " +this.token);
return new Promise(resolve => {
//, {headers: headers}
this.http.get(this.baseUrl+'/ovirt-engine/api/vms',{headers: headers}).subscribe(data => {
console.log(data);
resolve(data);
}, err => {
resolve(err)
console.log(err);
});
});
}
But I get 401 (Unauthorized)
What difference I have observed in the POST request which is working and the GET request is the headers.
Below is the screen shot from chrome inspect tool.
GET request header -
POST request header -
Why when I sent the GET request “Content-Type” and " Accept" header is not shown in the chrome in inspect tool?
Curl commands which works -
# curl -X POST -H 'Accept: application/json' -H 'Content-type: application/x-www-form-urlencoded' https://ovirt.example.com/ovirt-engine/sso/oauth/token -d "grant_type=password&scope=ovirt-app-api&username=admin%40example.com&password=xyz!"
# curl -X GET -H 'Accept: application/json' -H 'Content-type: application/x-www-form-urlencoded' -H 'Authorization: Bearer xxxxxtokenxxxxx https://ovirt.example.com/ovirt-engine/api/vms
Any help is appreciated
Thanks in advance.