1
我是新來的節點,並且難以概念化爲什麼您只會在一個POST請求上「塊」數據而不是GET請求?節點JS中的塊數據
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";
}
}
'GET'請求沒有主體。正文是以塊的形式發送的,所以「分塊」數據甚至不是一個選項,因爲這是請求發送的方式。我想這些頭文件(包含所有GET請求所需的數據)不是「塊」,但是我的http知識並不複雜。 –