我已经编写了这段代码,
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}}
我在哪里弄错了?