HTTP帖子离子显示错误

时间:2018-08-01 10:06:53

标签: angular post ionic-framework promise ionic3

我已经编写了这段代码,

ServiceProvider.ts

postData() {
  return new Promise((resolve, reject) => {

    var cred = {
      "username": "abc",
      "password": "password",
      "admin_channels": "[channel_abc]"
    };
    var header = {
      headers: {
        "Content-Type": "application/json"
      }
    };

    this.http.post(apiUrl + 'api/login', cred, header).subscribe(data => {
      resolve(data);
    }, err => {
      reject(err);
    });
  });
}

通过这种方式致电服务提供商

this.authService.postData().then((result) => {
  this.loading.dismiss();

  alert("full data " + JSON.stringify(result));

}, (err) => {
  this.loading.dismiss();
  alert(JSON.stringify(err)); //SHows ERROR HERE
});

这给了我这个错误:

  

{“标头”:{“ normalizedNames”:{},“ lazyUpdate”:null,“标头”:{}},“状态”:0,“ statusText”:“未知错误”,“ url”:null ,“ ok”:false,“ name”:“ HttpErrorResponse”,“ message”:“ Http失败响应(未知url):0未知错误”,“ error”:{“ isTrusted”:true}}

我在哪里弄错了?

0 个答案:

没有答案