我正在尝试使用cordova-plugin-http在Ionic 2应用程序中执行POST请求。 但是当我运行时,它正在服务器上运行GET方法。
import { HTTP } from 'ionic-native';
login(username:string, password:string){
return HTTP.post(APIHOST + 'login', {username:username, password:password},{});
}
有什么问题?
答案 0 :(得分:0)
//you need to import this//
import { Http, Headers, URLSearchParams, Request, RequestMethod, RequestOptions } from '@angular/http';
constructor(public navCtrl: NavController, private http: Http, private navParams: NavParams){}
//login function
Login(username, password) {
//body for your details to be verified
let data = {
"username": username,
"password": password,
}
//here you are making an api call//
return this.http
.post(apiUrl + Login, data)
.map(res => res.json())
.subscribe(
data => {
},
err => {
console.log("ERROR!: ", err);
}
);
}