skip to Main Content

I’ve setup my api into web server, currently im unable to retrieve data using my app key but able to do so using postman, please do help

const httpOptions = {
      headers: new HttpHeaders({
        'APP_KEY': 'ABCDEFGHJ'

      })
    };

    this.http.get('<my_api_link>', httpOptions).subscribe((res) => {
      this.Result = JSON.stringify(res);
      console.log('Result', this.DataResult);
    }, (err) => {
      console.error(err.status);
      console.error(err.error); // Error message as string
      console.error(err.headers);
    });

Error message was unable to find app key

4

Answers


  1. Try to set headers this way

    const httpHeaders = new HttpHeaders()
      .set('APP_KEY', 'ABCDEFGHJ');
    
    this.http.get('<my_api_link>', httpHeaders)
    
    Login or Signup to reply.
  2. Try this :

    var token = 'ABCDEFGHJ';
    const myHeaders = new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization': token });
    this.http.get('<my_api_link>', { headers: myHeaders });
    

    Or

    let headers = new HttpHeaders();
    headers = headers.set('APP_KEY','ABCDEFGHJ');
    
    Login or Signup to reply.
  3. Modifying your code snippet :

    const httpOptions = {
      headers: new HttpHeaders().set('APP_KEY', 'ABCDEFGHJ')
    };
    
    this.http.get('<my_api_link>', httpOptions).subscribe((res) => {
      this.Result = JSON.stringify(res);
      console.log('Result', this.DataResult);
    }, (err) => {
      console.error(err.status);
      console.error(err.error); // Error message as string
      console.error(err.headers);
    });
    
    Login or Signup to reply.
  4. import {HttpClient} from ‘@angular/common/http’;

    constructor(private _httpClient: HttpClient) {

    // some code

    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search