node点滴积累----http.createServer()

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属性的别名


猜你喜欢

转载自blog.csdn.net/enjoy_sun_moon/article/details/80492450