Ionic 2本地HTTP.post执行get on server

时间:2017-03-06 14:08:45

标签: cordova ionic-framework ionic2 cordova-plugins

我正在尝试使用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},{});
}

有什么问题?

1 个答案:

答案 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);
                    }
                    );
            }