关闭连接,但不显示消息

时间:2017-08-26 16:42:41

标签: node.js

我有以下代码并且它有效但不显示消息'太大的文件'。我看到一个带>>> from urllib.parse import parse_qsl >>> documentation_secret = 'NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j' >>> requestBody = parse_qsl('symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=6000000&timestamp=1499827319559') >>> calculate_signature(documentation_secret, requestBody) '24b39c6588d0f2378a2b641e68c00e87bc81d997146ca3c5482337857a045041' >>> queryString = parse_qsl('symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC') >>> requestBody = parse_qsl('quantity=1&price=0.1&recvWindow=6000000&timestamp=1499827319559') >>> calculate_signature(documentation_secret, requestBody, queryString) '77eb3b3727bc8c523646e2a35f52a8eb4cc4418b24c113f3ea0b3b59248579d4' 的chrome屏幕。如何关闭连接并显示消息?

ERR_CONNECTION_RESET

1 个答案:

答案 0 :(得分:0)

使用它。

var size = 0;

var sizeTooMuch = function(){
      console.log('aborting request');
      response.writeHead(413, 'Request Entity Too Large', {'Content-Type': 'text/html'});
      response.end('<!doctype html><html><head><title>413</title></head><body>Too big file 413</body></html>')          
      return false;
}

var gotData = function(d) {
    size += d.length;
    if(size > (1 * 1024 * 1024){
    sizeTooMuch();
   }
};

var endFunc = function(){
      console.log("got the file");
      res.send("got the file");
      res.end();
}

req.on('data', gotData);

req.on('end', endFunc);