离子2中的RESTAPI(POST方法)不适用于android设备
我们正在使用API在爱奥尼亚2中构建一个应用程序,API调用在浏览器(使用代理服务器)上运行良好 android构建(删除代理服务器)后,GET方法在设备上运行良好,但POST方法不起作用。它是一个用于用户身份验证的API,因此获得403禁止错误 代码如下:- Home.ts离子2中的RESTAPI(POST方法)不适用于android设备,android,rest,ionic2,Android,Rest,Ionic2,我们正在使用API在爱奥尼亚2中构建一个应用程序,API调用在浏览器(使用代理服务器)上运行良好 android构建(删除代理服务器)后,GET方法在设备上运行良好,但POST方法不起作用。它是一个用于用户身份验证的API,因此获得403禁止错误 代码如下:- Home.ts this.authService.checkAuthentication().then((res) =>{ console.log("Already authorized"); this.data = res;
this.authService.checkAuthentication().then((res) =>{
console.log("Already authorized");
this.data = res;
}, (err) => {
this.data = 'error occured';
});
ts(身份验证提供程序)
checkAuthentication() {
return new Promise((resolve, reject) => {
let credentials = {
email: 'test@test.com',
password: 'password'
};
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('X-XSRF-Token', 'kK4GDdiHAHejPeoXl4dL1AAgb13eiEwPhxvDw=');
let options = new RequestOptions({ headers: headers });
this.http.post(API_URL, JSON.stringify(credentials), options)
.map(res => res.json())
.subscribe((data) => {
resolve(data);
}, err => {
reject(err);
});
});
}