gpt4 book ai didi

javascript - 在 Node JS 中发送后无法设置 Header

转载 作者:行者123 更新时间:2023-12-03 07:06:19 31 4
gpt4 key购买 nike

发送后无法设置标题收到错误发送后无法设置 header ..我该如何解决此错误

app.post('/post', function (req, res) {

var diagnosis;

var obj = req.headers['data'];

var temp = JSON.parse(obj)
console.log("Received body data:");
console.log(obj);

MongoClient.connect(url, function (err, db) {
assert.equal(null, err);
insertDocument(temp, db, function () {
db.close();
});
});


var insertDocument = function (obj, db, callback) {
try {
console.log(obj);
db.collection('diagnosis').remove();
db.collection('diagnosis').insertOne(obj, function (err, result) {
assert.equal(err, null);
console.log("Inserted a document into the Diagnosis collection.");
callback();
});
res.send("Inserted a document into the Diagnosis collection.");
} catch (err) {
console.log(err);
}
};

res.send('Hello POST');})

我调用API的函数是

$scope.post = function () {

var diagnosis = $scope.Treatments;


var httpRequest = $http({
method: 'POST',
url: '/post',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'data': JSON.stringify($scope.Treatments)
},

}).success(function (data, status) {
});
};

最佳答案

此错误意味着:您已经发送了回复。我希望您阅读this 。对请求执行操作后,当您向您发送响应时,连接就会断开。

关于javascript - 在 Node JS 中发送后无法设置 Header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36808647/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com