TheUnreal
TheUnreal

Reputation: 24472

Angular HttpClientModule request headers

I'm trying to run an API call using the Angular HttpClientModule:

getUser(ticket) {
console.log(ticket); // Returns valid ticket
    return this.http.get('https://myapi/api/v1/flow-analysis', {
      headers: new HttpHeaders().set('X-Auth-Token', ticket)
    });
  }

When I'm running this API call in my client I get the folowing response:

'Failed to provide service ticket to validate'

I tried to run the same call in POSTMAN, and I got good response:

enter image description here

I'm using Chrome with this extension. Not sure if it causes the problem.

Any idea what could have gone wrong?

I'm using Angular 5

Upvotes: 0

Views: 1289

Answers (1)

Shino
Shino

Reputation: 131

You need to append the Content-Type header:

getUser(ticket: string) {
    console.log(ticket); // Returns valid ticket
    let headers: Headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
    headers.append('X-Auth-Token', ticket);

    return this.http.get('https://myapi/api/v1/flow-analysis', {
        headers: headers
    });
}

Upvotes: 1

Related Questions