Ionic Http appending header

I just set up my headers like this and it worked for me:

 const authorizationData = 'Bearer ' + user.accessToken;
        const headerOptions = {
            headers: new HttpHeaders({
                'Content-Type':  'application/json',
                Authorization: authorizationData
            })
        };

if your have username and password to send, you can use this also:

const authorizationData = 'Basic ' + btoa(this.key + ':' + this.key);
            const headerOptions = {
                headers: new HttpHeaders({
                    'Content-Type':  'application/json',
                    Authorization: authorizationData
                })
            };

After setting headers, pass it to httpClient something like this:

 this.httpClient.get(url,
            headerOptions).subscribe(res => {
                console.log(res);
        }, err => {
                console.log(err);
        });

I see this a lot on these forums. Generally, it’s not actively harmful, but sometimes it is, and if you’re using Angular’s HttpClient, I would argue that manually setting Content-Type is never necessary and should be avoided. HttpClient does this automatically for you based on the type of thing you pass as the request body, and to maintain flexibility and focus attention on the important part of code, I suggest leaving the manual declaration out.