xhr send-发送文件和CSRF令牌 [英] xhr send - send file and CSRF token

查看:83
本文介绍了xhr send-发送文件和CSRF令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用XMLHttpRequest将文件对象和字符串(CSRF令牌)发送到服务器,但是我似乎无法弄清楚如何添加令牌:

I'm trying to use XMLHttpRequest to send a file object and a string (CSRF Token) to the server but I cant seem to figure out how to add the token:

xhr.open("POST", form.action, true);
xhr.setRequestHeader("X_FILENAME", file.name);
xhr.send(file);

正在发送文件,有人帮助如何附加令牌吗?

is sending the file, anyone lend a hand on how to attach the token?

致谢

推荐答案

为什么不只是添加

xhr.setRequestHeader('X-CSRF-TOKEN', '<YOURTOKENHERE>');

在xhr.send()之前?

before xhr.send() ?

据我了解您的问题,这应该可以解决. (不过,可能是我误会了)

As far as I understand your problem, this should solve it. (Might be I misunderstood, though)

这篇关于xhr send-发送文件和CSRF令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆