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)
});
輸出:
相關用法
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js http.ClientRequest.writableFinished API。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。