I have some raw json that I'm trying to send to my back end server in mysql.
(我有一些原始的json,我正尝试发送到mysql的后端服务器。)
I'm currently trying to loop through the specific array in the json that I need and sending data from each of the children in the array via a POST request but I am getting "Cannot set headers after they are sent to the client". (我目前正在尝试遍历所需的json中的特定数组,并通过POST请求从数组中的每个子级发送数据,但是我收到“在将标头发送到客户端后无法设置标头”。)
app.post('/reddit-import', function (req, res) {
console.log("Route /reddit-import POST");
let data = req.body.data.children
data.forEach(child => {
let sql1 = `CALL insert_user('${child.data.author}',
'${child.data.author_fullname}');`
connection.query(sql1,
data,
function (errQuery, result) {
if (errQuery) {
console.log(errQuery);
res.json({status: "Error", err: errQuery});
res.end();
} else {
console.log("Insert ID: ", result.insertId);
res.json({status: result.insertId, err: ""});
res.end();
}
}
);
When I send the POST request, my backend gets 2 rows of data before it hits me with the error message...any ideas?
(当我发送POST请求时,我的后端会收到2行数据,然后它会出现错误消息,这使我震惊……有什么想法吗?)
ask by johntc121 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…