Header in HTTP GET request

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 -

Screenshot%20from%202019-01-13%2016-40-02

POST request header -

Screenshot%20from%202019-01-13%2016-43-32

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 :slight_smile:

Thanks in advance.