0

I want to set "API Key" and "Accept" in HTTP header. I would also like to add auth-token, page-no, page-size in the body. Can anybody help me?

Below is the code snippet I tried so far :

const body = {
            auth_token: '',
            type: 'matrix',
            page_no: '1',
            page_size: '20',
            keyword: 'j',
        };
        const header = new HttpHeaders();
        header.append('X-API-KEY', '');
        header.append('Accept', 'application/json');
         return this.http.get('', { headers: header} **body**)
            .map
            (
                (reponse: Response) => {
                    const resp = reponse.json();
                    return resp;
                }
            );
    }
2
  • Please put your code inside code block so users can read easily. Commented Mar 26, 2018 at 7:16
  • done i also want to send body with headers Commented Mar 26, 2018 at 7:26

2 Answers 2

1

Instance of HttpHeaders is immutable, you have to do: let headers = new HttpHeaders(); headers = headers.append('X-API-KEY', '');

Sign up to request clarification or add additional context in comments.

Comments

1

Another way is

const header=new HttpHeader({
   'X-API-KEY': '',
   'Accept': 'application/json'
})

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.