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


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


http.ClientRequest.writableEnded 是 http 模块中 ClientRequest 类的内置应用程序编程接口,用于检查 request.end() 是否已被调用。

用法:

const request.writableEnded

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

返回值:当且仅当 request.end() 已被调用时,此方法返回 true。

范例1:



index.js


// Node.js program to demonstrate the  
// request.writableEnded 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 clinet request
  const req = http.request(options);
  
  // checking if the request.end() has been called
  // by using writableEnded api
  if(req.writableEnded)
  console.log('request.end() has been called')
  else
  console.log('request.end() has not been called')
  
  process.exit(0)
});

输出:

相关用法


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