如何在ionic3中调用没有form-data的POST API?
How to call POST API without form-data in ionic3?
嗨,我已经在没有 headers 的情况下触发了 POST api 但是我们的 API 被正确调用但是每次都得到以上错误错误的参数,但是在 PostMan 中它告诉我,任何人,我的代码有什么问题?**
//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);
});
}
试试这个代码:
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
嗨,我已经在没有 headers 的情况下触发了 POST api 但是我们的 API 被正确调用但是每次都得到以上错误错误的参数,但是在 PostMan 中它告诉我,任何人,我的代码有什么问题?**
//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);
});
}
试试这个代码:
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