我采取了CSRF失败错误;
加载资源失败:服务器响应状态为 403(禁止访问(
响应 _body:"{"detail":"CSRF 失败:引用器检查失败 - 无引用器。 标头:标头 正常:假 状态: 403 状态文本:"禁止" 类型: 2 网址:"https://deneme.com/api/v1.0/channels/">
我的代码;
uyegiris()
{
var veri,kullaniciveri;
this.deneme=2;
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/x-www-form-urlencoded' );
//headers.append('Authorization' , 'Basic '+ btoa(tok));
let options = new RequestOptions({ headers: headers });
let postParams = {
username: this.user['usernameil'],
password:this.user['password'],
}
this.http.post("https://deneme.com/api/v1.0/users/login/", postParams, options).timeout(2000)
.subscribe(data => {
veri = data['_body'];
veri= veri.slice(1, -1);
veri = veri.replace(/\/g, "");
veri = JSON.parse(veri);
console.log(veri);
if(veri.msg_err)
{
let alert = this.alertCtrl.create({
title: 'Giriş Hatası',
subTitle: veri.msg_err,
buttons: ['Tamam']
});
alert.present();
}
else
{
this.kanallistele();
}
}, error => {
console.log(error);
this.deneme=error;
});
}
kanallistele()
{
var veri;
this.kanallardiv=true;
this.uyegirisdiv=false;
this.kanallistelebtn = false;
this.kanallistelebtn2 = false;
var headers = new Headers();
headers.append('Accept', 'application/json');
headers.append('Content-Type', 'application/json' );
//headers.append('Authorization' , 'Basic '+ btoa(tok));
let options = new RequestOptions({ headers: headers });
let postParams = {
token: "381f13d7056-ce5fe474919",
user_id: "71",
}
var veris="channel_name_";
this.http2.post("https://deneme.com/api/v1.0/channels/", postParams, options)
.subscribe(data => {
veri = data['_body'];
console.log(veri);
veri= veri.slice(1, -1);
veri = veri.replace(/\/g, "");
veri = JSON.parse(veri);
for(var i = 0 ;;i++)
{
if(!veri.channel_list['channel_name_' + (i)])
break;
this.veriler.push({channelname: veri.channel_list['channel_name_' + (i)],channelid: veri.channel_list['channel_id_' + (i)]});
}
}, error => {
console.log(error);
this.deneme=error;// Error getting the data
});
}
这与Ionic无关。看起来您的服务器/后端/任何东西都需要一些CSRF令牌来响应您的请求,并且您没有附加它们。您应该联系后端团队,以便将缺少的令牌添加到您的请求中