# Change Http to HttpClient , now post method not working

**URL:** <https://forum.ionicframework.com/t/change-http-to-httpclient-now-post-method-not-working/117920>\
**Category:** ionic-v3\
**Created:** [January 11, 2018, 10:02am UTC](https://forum.ionicframework.com/t/change-http-to-httpclient-now-post-method-not-working/117920 "2018-01-11T10:02:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anespa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/anespa/32/116051_2.png) [@anespa](https://forum.ionicframework.com/u/anespa)\
**Post date:** [January 11, 2018, 10:02am UTC](https://forum.ionicframework.com/t/change-http-to-httpclient-now-post-method-not-working/117920/1 "2018-01-11T10:02:12Z")

</div>

Dear Friends,  
I change from ‘Http’ to ‘HttpClient’ method as described in AngularJS 4.3 or above. Now one of my workig form stop working. The request and response work fine but the data get return on the function is ‘null’.

my problematic page ts file here

```auto
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators, AbstractControl } from '@angular/forms';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
//import { Http } from '@angular/http';
import { HttpClient } from '@angular/common/http';

/**
 * Generated class for the PaymentPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-birth-certificate',
  templateUrl: 'birth-certificate.html',
})

export class BirthCertificatePage {
  formgroup:FormGroup;
  username:AbstractControl;
  data:any = {};

  
constructor(public navCtrl: NavController, public navParams: NavParams, public http: HttpClient, public formbuilder: FormBuilder ) {
     this.formgroup = formbuilder.group({
       username:['',Validators.required]
     });
     this.username = this.formgroup.controls['username'];
     this.data.username = '';
     this.data.response = '';
     this.http = http;
  }
  submit() {
   var link = 'http://nikola-breznjak.com/_testings/ionicPHP/api.php';
   var obj = {username: this.data.username};
   var myData = JSON.stringify(obj);
   alert(myData); //ALERT DATA HERE ON FORM SUBMIT
   this.http.post(link, myData)
   .subscribe(data => {
   //this.data.response = data["_body"]; //https://stackoverflow.com/questions/39574305/property-body-does-not-exist-on-type-response

   alert(data); //RETURNS NULL VALUE
   //this.data.response = data;
   }, error => {
   console.log("Oooops!");
   });
 }

  ionViewDidLoad() {
    console.log('ionViewDidLoad BirthCertificatePage');
  }

}

```

Please advise I am hanging on this problem for 4 hours

Thanks

Anes

---

<div class="post-metadata">

**Author:** ![mfouash](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mfouash/32/112535_2.png) [@mfouash](https://forum.ionicframework.com/u/mfouash)\
**Post date:** [February 1, 2018, 1:57pm UTC](https://forum.ionicframework.com/t/change-http-to-httpclient-now-post-method-not-working/117920/2 "2018-02-01T13:57:53Z")

</div>

i face the same problem ☹

---

<div class="post-metadata">

**Author:** ![szerletics](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@szerletics](https://forum.ionicframework.com/u/szerletics)\
**Post date:** [February 1, 2018, 2:15pm UTC](https://forum.ionicframework.com/t/change-http-to-httpclient-now-post-method-not-working/117920/3 "2018-02-01T14:15:42Z")

</div>

Set your header…

```auto
{headers: {'Content-Type': 'application/json'}

```

---

<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:55pm UTC](https://forum.ionicframework.com/t/change-http-to-httpclient-now-post-method-not-working/117920/4 "2021-07-19T21:55:50Z")

</div>


