问题
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