NODEJS[21]:http模块_设置响应报文
·
Yin灏
const http = require("http");
const server = http.createServer((request, response) => {
// 1. 响应状态码
response.statusCode = 200;
// 2. 响应状态描述
response.statusMessage = "xxxx";
// 3. 响应头
response.setHeader("content-type", "text/html;charset=utf-8");
// 4. 响应体设置
// 下面多个会拼在一起返回给前端
response.write("love");
response.write("love");
response.write("love");
response.end(); // 上面 response.write 设置了值,这里就不在设置
});
server.listen(9000, () => {
cons.log("服务器已经启动了...");
});