xhr send - send file and CSRF token

帅比萌擦擦* 提交于 2019-12-31 04:30:30

问题


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?

regards


回答1:


Why don't you just add

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

before xhr.send() ?

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



来源:https://stackoverflow.com/questions/36060490/xhr-send-send-file-and-csrf-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!