未设置CSRF令牌..如何在Typescript中设置CSRF cookie?

2024-04-25 05:09:52 发布

您现在位置:Python中文网/ 问答频道 /正文

作为标题,我不知道如何在我的typescript文件中设置CSRF令牌,我是一个关于typescript和CSRF令牌的初学者。

这是我用来发布信息的typescript文件。

getUsers2() {

    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    let body2 = {
      site: this.selectedSite,
      zone: this.selectedZone,
      user: this.username,
      categoryType: this.problemType,
      ser: 'High',
      conNo:'012-8888888'
    };

    this.http.post('http://localhost:8000/apidb/report/', JSON.stringify(body2), {headers: headers})
        .map(res => res.json())
        .subscribe(data => {
            console.log("herererererere" ,data);
        });


    this.restProvider.getUsers2().then(data2 => {
      this.locations = data2;
      console.log(this.locations);
    });
  }

在我的内心设置.py我已经安装中间件了

^{pr2}$

在我的视图.py我不确定这是不是正确

^{pr3}$

当我将数据发布到API时,它显示CSRF未设置。。

enter image description here

有人能给我提供关于这个问题的指导或指导吗??谢谢!!


Tags: 文件logjsonhttpdataresthiscsrf
1条回答
网友
1楼 · 发布于 2024-04-25 05:09:52

您必须将CSRF令牌附加到HTTPrequest中发送的POSTdata(在本例中是body2var)。你必须检查Django文档在POST中寻找的名称(在Laravel中,它的''u token')。在

此POST var的值将通过在页面顶部回显令牌服务器端来设置(即var x=(CSRF token的服务器端echo);)

相关问题 更多 >