当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js http.ClientRequest.writableFinished用法及代码示例


http.ClientRequest.writableFinished 是 http 模块中 ClientRequest 类的内置应用程序编程接口,用于检查所有数据是否已刷新。

用法:

const request.writableEnded

参数:此 API 不接受任何参数作为参数。

返回值:当且仅当所有数据都已刷新时,此方法返回 true。

范例1:



index.js


// NodeJS program to demonstrate the  
// request.writableFinished APi
  
// Importing http module
const http = require('http');
  
// Create an HTTP server
const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type':'text/plain' });
  res.end('okay');
});
  
// Now that server is running
server.listen(3000, '127.0.0.1', () => {
  
  // make a request
  const options = {
    port:3000,
    host:'127.0.0.1',
    headers:{
      'Connection':'Upgrade',
      'Upgrade':'websocket'
    }
  };
  
  // getting client request
  const req = http.request(options);
  
  // checking if the all data has been flushed
  // by using writableFinished api
  if(req.writableFinished)
  console.log('all data has been flushed')
  else
  console.log('all data has not been flushed')
  
  process.exit(0)
});

输出:

相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js http.ClientRequest.writableFinished API。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。