Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Node.js HTTP ServerResponse 对象

❮ requestListener


示例

ServerResponse 对象作为第二个参数传递给 requestListener 函数

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');
  res.end();
}).listen(8080);
运行示例 »

定义和用法

ServerResponse 对象作为第二个参数传递给 requestListener 函数。

ServerResponse 对象表示写回客户端的可写流。


ServerResponse 方法和属性

addTrailers() 添加 HTTP 尾部报头
end() 指示服务器认为响应已完成
finished 如果响应已完成,则返回 true,否则返回 false
getHeader() 返回指定报头的值
headersSent 如果已发送报头,则返回 true,否则返回 false
removeHeader() 移除指定报头
sendDate 设置为 false 表示在响应中不发送 Date 报头。默认值为 true
setHeader() 设置指定报头
setTimeout 将套接字的超时值设置为指定的毫秒数
statusCode 设置将发送到客户端的状态代码
statusMessage 设置将发送到客户端的状态消息
write() 将文本或文本流发送到客户端
writeContinue() 向客户端发送 HTTP Continue 消息
writeHead() 向客户端发送状态和响应报头

❮ requestListener

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.