标签:
var http= require(‘http‘ ); var url= require(‘url‘ ); function start (){ function onRequest(request ,response){ var pathname =url .parse(request .url) .pathname ;// url.parse()解析请求头的url地址 var query =url .parse(request .url) .query ; response .writeHead(200 ,{ ‘Content-Type‘ :‘text/plain; charset=utf-8‘}) ; response .write( "请求路径为:" +pathname +‘ ‘ ); response .write( "请求参数为:" +query +‘ ‘ ); response .write( "我是响应头的信息" ); response .end() ;//响应结束 } http .createServer(onRequest) .listen(9999) ; console .log( "服务器启动完成" ); } start() ;
标签:
原文地址:http://www.cnblogs.com/yunyi1895/p/5801946.html