标签:local bubuko body dom zab \n isp 字符 char
后台express需要connect-multiparty模块接收formData的数据类型
const random = (a, b) => Math.floor(Math.random() * (b - a + 1) + a);
function randomString32(len) {
// 默认返回32位随机字符串
const loopn = len || 32;
const c = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
const c_len = c.length;
let res = '';
for (let i = 0; i < loopn; i++) {
res += c.charAt(random(0, c_len - 1));
}
return res;
}
let xhr = new XMLHttpRequest;
xhr.open('post', 'http://localhost:3000/');
// let data = new FormData();
// data.append('name', 'ajanuw')
// data.append('age', '14')
// xhr.send(data);
let rs = randomString32(16);
let data_string = '\r\n'
data_string +=
`------WebKitFormBoundary${rs}\r\nContent-Disposition: form-data; name="name"\r\n\r\nalone\r\n`;
data_string +=
`------WebKitFormBoundary${rs}\r\nContent-Disposition: form-data; name="age"\r\n\r\n12\r\n`;
data_string += `------WebKitFormBoundary${rs}--`
xhr.setRequestHeader('Content-Type', `multipart/form-data; boundary=----WebKitFormBoundary${rs}`);
xhr.send(data_string);
xhr.onload = e => {
console.log(xhr.response);
}
router.post('/', function (req, res, next) {
l(req.body)
res
.set({
'access-control-allow-origin': '*'
})
.send('hello');
});
标签:local bubuko body dom zab \n isp 字符 char
原文地址:https://www.cnblogs.com/ajanuw/p/9371288.html