我正在尝试使用带有离子2的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插件
答案 0 :(得分:0)
let body = "username="+username+"&password="+password;
let headers = new Headers({
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
});
let options = new RequestOptions({
headers: headers,
body: body
});
this.http.post(url, body, options)
.subscribe(