2015-09-13 37 views
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"; 
    } 
} 
+0

'GET'請求沒有主體。正文是以塊的形式發送的,所以「分塊」數據甚至不是一個選項,因爲這是請求發送的方式。我想這些頭文件(包含所有GET請求所需的數據)不是「塊」,但是我的http知識並不複雜。 –

回答

0

當使用POST方法用戶發送數據到服務器,我們需要分析所以需要查全部數據。 當使用GET服務器向用戶發送數據時,服務器沒有獲取數據,不需要查詢