在 Node JS 中分块数据
Chunking Data in Node JS
我是 node 的新手,我无法理解为什么你会 "Chunk" 数据只在 POST 请求而不是 GET 请求?
if (request.method === "POST") {
if (request.url === "/classes/messages" || request.url === "/classes/room1") {
var statusCode = 201;
var headers = defaultCorsHeaders;
var body = '';
request.on('data', function(data) {
console.log("receiving data....", body);
body += data;
});
//request ended, you can now do something with the data
request.on('end', function() {
var bodyObj = JSON.parse(body);
bodyObj.objectId = Math.random() * 10;
responseObj['results'].push(bodyObj);
// request ended -> do something with the data. set the headers.
response.writeHead(statusCode, headers);
//writing the data to json
//response.write();
//ending the response.
response.end(JSON.stringify(responseObj));
});
//headers['Content-Type'] = "text/plain";
}
}
当使用 POST 方法时,用户将数据发送到服务器,我们需要分析,因此需要查出所有数据。
使用GET服务器向用户发送数据时,服务器取不到数据,不需要chuck
我是 node 的新手,我无法理解为什么你会 "Chunk" 数据只在 POST 请求而不是 GET 请求?
if (request.method === "POST") {
if (request.url === "/classes/messages" || request.url === "/classes/room1") {
var statusCode = 201;
var headers = defaultCorsHeaders;
var body = '';
request.on('data', function(data) {
console.log("receiving data....", body);
body += data;
});
//request ended, you can now do something with the data
request.on('end', function() {
var bodyObj = JSON.parse(body);
bodyObj.objectId = Math.random() * 10;
responseObj['results'].push(bodyObj);
// request ended -> do something with the data. set the headers.
response.writeHead(statusCode, headers);
//writing the data to json
//response.write();
//ending the response.
response.end(JSON.stringify(responseObj));
});
//headers['Content-Type'] = "text/plain";
}
}
当使用 POST 方法时,用户将数据发送到服务器,我们需要分析,因此需要查出所有数据。 使用GET服务器向用户发送数据时,服务器取不到数据,不需要chuck