如何在ionic3中调用不带表单数据的POST API?

时间:2019-01-03 14:02:36

标签: ionic3 form-data

嗨,我已经触发了没有标头的POST api,但是我们的API却被正确调用,但是每次都会出现错误错误参数,但是在PostMan中它可以告诉m,任何人,我的代码有什么问题?**

//hgome page
  goToContinue() {
    //
    var param = {
        code : this.uniqueCode
    }

   this.service.checkLogin(function(isSuccess, data) {
      //set the new page....
      this.navCtrl.setRoot('SliderPage'); 
   }, param)
  }
  
  ///service class
  checkLogin(callback : any, value : any) {

    this.http.
    post(https://ams.code.co.in/auth/checkschoolcode', value).subscribe((data:any) => {
      callback(true, data);
    },err => {
         console.log('ddd' +err);
    });
}

1 个答案:

答案 0 :(得分:2)

尝试以下代码:

this.headers = {'Content-Type':'application/json'}; this.http.post('your API URL', JSON.stringify('Your Data Variable'), {headers: this.headers}) .map(res => res.json()) .subscribe(data => { console.log(data); });

否则,您将拥有用于IONIC的本地插件来调用HTTP请求。 check this plugin