ionic2 http post未发送参数
我正在尝试将http post与ionic 2一起使用,但无法向服务器发送参数ionic2 http post未发送参数,ionic2,Ionic2,我正在尝试将http post与ionic 2一起使用,但无法向服务器发送参数 import {Http, Headers, RequestOptions} from "@angular/http"; import 'rxjs/add/operator/map'; constructor(public navCtrl: NavController, public navParams: NavParams, public shareServices: ShareServices, public
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插件
你能抓住任何错误吗?也许你可以这样试试:
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(
您有任何错误吗?没有,没有找到错误谢谢,它对我有效,但我如何才能以JSONthis.http.post(url、正文、选项)的形式获得响应。订阅(response=>{var result=response.json();//result is json object},error=>{console.log('error');});