Http native header not sending

I am developing an app with HTTP. I want to send the data with headers. Data is successfully sending without header.
I am used the steps in

the code is

let header = new HttpHeaders();
header = header.set('a', 'abc');'/login', {postParams}, {header}).then(data => {
        console.log(; // data received by server
    var json = JSON.stringify(data.headers);

.catch(error => {

    console.log(error.status); // showing as "undefined"
    console.log(error.error); // showing as "undefined"
    console.log(error.headers); // showing as "undefined"

The import files are

import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Headers, RequestOptions  } from '@angular/http';
import { HTTP } from '@ionic-native/http';

I have tried different methods but not getting the result.

If adding'/login', {postParams}, {})

Geeting the result but when adding'/login', {postParams}, {header})

Errors showing “undefined” .

Please help me.

Please check with your backend team that whether they are accepting headers in URL

I check the backend not accepting when adding header in request. But in postman it is working.

I got the solution when i add header directly in the request.'/login', {postParams}, {"Content-Type": "application/json","auth":"anbnvbnhvbnbnvbnvbnbnbn"})

This is working for me.

1 Like