发送后无法设置标题 获取错误发送后无法设置标题..如何解决此错误
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) {
});
};