0

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

1 Answer 1

1

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
    });
}
Sign up to request clarification or add additional context in comments.

3 Comments

@TobySpeight is that better?
This is not compactiable with the latest Angular. I'm using Angular HttpclientModule. with your solution I get Type 'HttpHeaders' is not assignable to type 'Headers'.
@TheUnreal these changes worked for me: import { HttpClient, HttpHeaders } from '@angular/common/http'; let headers: HttpHeaders = new HttpHeaders();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.