Я выполняю http-запрос в nodejs, но запрос никогда не заканчивается и продолжаю выполнять следующий код. он только печатает «конец ответа», но никогда не «конец запроса». Почему он будет вести себя так?
const post_data = JSON.stringify({
'username': username,
'org': orgName,
'peers': peers,
'channelName': channelName,
'chaincodeName': chaincodeName,
'fcn': fcn,
'args': args
});
var post_options = {
host: 'localhost',
port: '3000',
path: '/cc/write',
method: 'POST',
headers: {
"content-type": "application/json",
"Content-Length": Buffer.byteLength(post_data)
}
};
var post_req = http.request(post_options, function (res) {
console.log("connected");
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
ccResponse = chunk;
});
res.on('end', function () {
console.log('response end')
});
});
// post the data
post_req.write(post_data);
post_req.on('end', function () {
console.log('request end');
});
post_req.on('finish', function () {
console.log('request end');
});
post_req.end();
console.log("Random thing");