我試圖使用HTTP POST與離子2,但ionic2 HTTP POST不發送參數
import {Http, Headers, RequestOptions} from "@angular/http";
import 'rxjs/add/operator/map';
constructor(public navCtrl: NavController, public navParams: NavParams, public shareServices: ShareServices, public http: Http) {
this.data = {};
this.data.email = '';
this.data.password = '';
}
login()
{
let url = 'http://localhost/wp/ap/user/generate_auth_cookie/?insecure=cool';
var headers = new Headers();
headers.append("Accept", 'application/json');
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let body = {
email : this.data.username,
password : this.data.password,
}
this.http.post(url,JSON.stringify(body), options).map(res => res.json()).subscribe(
data => {
this.resp = data.json();
console.log('RESP', this.resp);
},
err => {
this.resp = err.json();
console.log('ERROR', this.resp);
}
);
}
我使用WordPress的用戶API插件
我不能將參數傳遞給服務器
你有什麼錯誤? – Sampath
沒有,沒有發現錯誤 – MSalah