node.js中的http.response.write方法使用說明
更新時間:2014年12月14日 10:14:44 投稿:junjie
這篇文章主要介紹了node.js中的http.response.write方法使用說明,本文介紹了http.response.write的方法說明、語法、接收參數(shù)、使用實例和實現(xiàn)源碼,需要的朋友可以參考下
方法說明:
向請求的客戶端發(fā)送響應內容。
在 response.end() 之前,response.write() 可以被執(zhí)行多次。
語法:
復制代碼 代碼如下:
response.write(chunk, [encoding])
參數(shù):
chunk 是一個buffer 或 字符串,表示發(fā)送的內容
encoding 如果chunk是字符串,就需要指定encoding來說明它的編碼方式,默認utf-8
例子:
復制代碼 代碼如下:
var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-type' : 'text/html'});
res.write('<h1>Node.js</h1>');
res.end('<p>Hello World</p>');
}).listen(3000);
您可能感興趣的文章:
- 完美解決node.js中使用https請求報CERT_UNTRUSTED的問題
- node.js請求HTTPS報錯:UNABLE_TO_VERIFY_LEAF_SIGNATURE\的解決方法
- Node.js中Request模塊處理HTTP協(xié)議請求的基本使用教程
- node.js中的http.request方法使用說明
- node.js中的http.createServer方法使用說明
- node.js中的http.get方法使用說明
- node.js中的http.response.end方法使用說明
- node.js中的http.response.writeHead方法使用說明
- node.js中的http.response.setHeader方法使用說明
- 淺析Node.js實現(xiàn)HTTP文件下載
- Node.js中HTTP模塊與事件模塊詳解
- Node.js發(fā)送HTTP客戶端請求并顯示響應結果的方法示例