【发布时间】:2016-05-15 20:54:25
【问题描述】:
我想将 csrftoken 从 node.js 传递给 django。我的 server.js 中有这段代码
socket.on('unread global', function (data) {
var values=querystring.stringify();
var options = {
hostname:'localhost',
port:'8000',
path:'/chat/global_unread/',
method:'POST',
headers:{
'Content-Type':'application/x-www-form-urlencoded',
'Cookie': 'csrftoken=' + data.csrf,
'Content-Length':values.length
}
}
我的数据来自调用我的 server.js 的 jquery 函数
var datos = { // datos is the data that will be send to Node.js
user: USER_PK_CHAT,
csrf : window.CSRF_TOKEN
};
socket.emit('unread global', datos);
但最后我的控制台中总是出现同样的错误
失败原因:
CSRF token missing or incorrect.
一般来说,当存在真正的跨站请求伪造时,或者
对于 POST 表单,您需要 确保:
您的浏览器正在接受 cookie... 等等 有人可以帮助我吗?
【问题讨论】:
-
很可能令牌不正确。您需要检查有关初始请求以检索令牌的更多详细信息。
-
Django 和 node.js 几乎可以肯定使用不同的机制来生成 CSRF 令牌。
标签: javascript jquery django node.js