var http = require("http")
http.createServer(function(req,res){//回调函数
console.log(req.httpVersion);
console.log(req.headers);
console.log(req.method);
console.log(req.url);
console.log(req.trailers);
console.log(req.complete);
res.writeHead(200,{'Content-Type':'text/html'});
res.write("holloe world")
res.end("fdsa");
}).listen(8000);
console.log(1)//先执行这个 再执行function中的req的调用函数会输出在浏览器中
总结res和req的属性与方法:
1. http.ServerRequest的属性
request对象的属性是:
| 名称 | 含义 |
|---|---|
| complete | 描述这个请求信息是不是发送完成了 |
| httpVersion | 描述HTTP协议版本,通常是1.0或者1.1 |
| method | 描述HTTP请求方法,比如GET,POST,PUT,DELETE等 |
| url | 描述原始的请求路径 |
| headers | 描述HTTP请求头 |
| trailers | 描述HTTP请求尾 |
| connection | 描述当前的HTTP连接套接字,是net.Socket的实例 |
| socket | connection属性的别面,套接字 |
| client | client属性的别名 |
本文介绍如何使用Node.js创建一个简单的HTTP服务器,并详细解释了http.ServerRequest对象的属性,包括请求的各种信息如HTTP版本、方法、URL等。
1239

被折叠的 条评论
为什么被折叠?



