Node.js 相同的HTTP请求,不同的HTTP头

Node.js 相同的HTTP请求,不同的HTTP头,node.js,http-request,chunked,Node.js,Http Request,Chunked,我正在开发一个Node.js应用程序(Heroku中允许),它会生成response.write()并写入JSON文本。使用这个工具,我可以测试这些http请求,但我不明白为什么在同一个http请求中,有时出现第一个头,有时出现另一个头 我只想要第一个。我怎么能总是有第一个,而从来没有第二个 HEADERS Connection: Close Content-Length: 877 Content-Type: application/json Date: Wed, 26 Mar 2014 00

我正在开发一个Node.js应用程序(Heroku中允许),它会生成response.write()并写入JSON文本。使用这个工具,我可以测试这些http请求,但我不明白为什么在同一个http请求中,有时出现第一个头,有时出现另一个头

我只想要第一个。我怎么能总是有第一个,而从来没有第二个

HEADERS

Connection: Close
Content-Length: 877
Content-Type: application/json
Date: Wed, 26 Mar 2014 00:25:06 GMT
或者有时候

HEADERS

Connection: Close
Content-Type: application/json
Date: Wed, 26 Mar 2014 00:27:22 GMT
Transfer-Encoding: chunked
正如你所看到的,我不知道这可能是什么,所以我不知道哪些信息对分享有用。所以,如果你有任何想法,请分享

JSON来自使用mysql npm的SQL查询。比如:

var mysql      = require('mysql');
var db_config = {...};
var connection;

function handleDisconnect() {
console.log('1. connecting to db:');
connection = mysql.createConnection(db_config); // Recreate the connection, since
                                                // the old one cannot be reused.

connection.connect(function(err) {                  // The server is either down
    if (err) {                                     // or restarting (takes a while sometimes).
        console.log('2. error when connecting to db:', err);
        setTimeout(handleDisconnect, 1000); // We introduce a delay before attempting to reconnect,
    }                                       // to avoid a hot loop, and to allow our node script to
});                                         // process asynchronous requests in the meantime.
                                            // If you're also serving http, display a 503 error.
connection.on('error', function(err) {
    console.log('3. db error', err);
    if (err.code === 'PROTOCOL_CONNECTION_LOST') {  // Connection to the MySQL server is usually
        handleDisconnect();                         // lost due to either server restart, or a
    } else {                                        // connnection idle timeout (the wait_timeout
        throw err;                                  // server variable configures this)
    }
});
}

handleDisconnect(); 
console.log(id);



connection.query("select * from table where id = '"+id+"'", function(err, rows, fields){
if (err){
    console.log(err);
    throw err;
}
var objToJson = rows;
objToJson.response = response;
var finalresponse = JSON.stringify(objToJson);

response.write('{ "firstdata": ')
response.write(finalresponse);


var jsonResult = JSON.parse(finalresponse);
var ordersplit = jsonResult[0].order_split


if(ordersplit == 0){

    connection.query("Call getUnit('"+id+"');", function(err, rows, fields){
        if (err){
            console.log(err);
            throw err;
        }
        var objToJson = rows[0];
        objToJson.response = response;
        response.write(', "data": ');
        response.write(JSON.stringify(objToJson));
        response.write('}');
        response.end();

    });
}


if(ordersplit == 1){

    connection.query("Call getUnitCustomize('"+id+"');", function(err, rows, fields){
        if (err){
            console.log(err);
            throw err;
        }
        var objToJson = rows[0];
        objToJson.response = response;
        response.write(', "data": ');
        response.write(JSON.stringify(objToJson));
        response.write('}');
        response.end();

    });
}

connection.end();
});

您发送的JSON来自何处?请检查上次更新:)@loganfsmyth