# Http native header not sending

**URL:** <https://forum.ionicframework.com/t/http-native-header-not-sending/137084>\
**Category:** Ionic Native\
**Created:** [August 2, 2018, 7:26am UTC](https://forum.ionicframework.com/t/http-native-header-not-sending/137084 "2018-08-02T07:26:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![faziltm](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@faziltm](https://forum.ionicframework.com/u/faziltm)\
**Post date:** [August 2, 2018, 7:26am UTC](https://forum.ionicframework.com/t/http-native-header-not-sending/137084/1 "2018-08-02T07:26:03Z")

</div>

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

> **[Ionic Framework](https://ionicframework.com/docs/native/http/)**
>
> Ionic is the app platform for web developers. Build amazing mobile, web, and desktop apps all with one shared code base and open web standards

the code is

```auto
let header = new HttpHeaders();
header = header.set('a', 'abc');

    this.http.post(this.apiUrl+'/login', {postParams}, {header}).then(data => {
        console.log(data.status);
        console.log(data.data); // data received by server
        console.log(data.headers);
    var json = JSON.stringify(data.headers);
    console.log(JSON.stringify(data.headers["x-auth-token"]));

})
.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

```auto
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

```auto
this.http.post(this.apiUrl+'/login', {postParams}, {})

```

Geeting the result but when adding

```auto
this.http.post(this.apiUrl+'/login', {postParams}, {header})

```

Errors showing “undefined” .

Please help me.

---

<div class="post-metadata">

**Author:** ![yashwanth493](https://avatars.discourse-cdn.com/v4/letter/y/a183cd/32.png) [@yashwanth493](https://forum.ionicframework.com/u/yashwanth493)\
**Post date:** [August 2, 2018, 12:01pm UTC](https://forum.ionicframework.com/t/http-native-header-not-sending/137084/2 "2018-08-02T12:01:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![faziltm](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@faziltm](https://forum.ionicframework.com/u/faziltm)\
**Post date:** [August 3, 2018, 4:24am UTC](https://forum.ionicframework.com/t/http-native-header-not-sending/137084/3 "2018-08-03T04:24:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![faziltm](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@faziltm](https://forum.ionicframework.com/u/faziltm)\
**Post date:** [August 3, 2018, 4:46am UTC](https://forum.ionicframework.com/t/http-native-header-not-sending/137084/4 "2018-08-03T04:46:28Z")

</div>

I got the solution when i add header directly in the request.

```auto
this.http.post(this.apiUrl+'/login', {postParams}, {"Content-Type": "application/json","auth":"anbnvbnhvbnbnvbnvbnbnbn"})

```

This is working for me.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:26pm UTC](https://forum.ionicframework.com/t/http-native-header-not-sending/137084/5 "2021-07-19T21:26:22Z")

</div>

Closed on July 19, 2021, 9:26pm UTC


