首先要创建一个node服务器
[JavaScript]
纯文本查看
复制代码
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 | var http = require("http"); var url = require("url");http.createServer(function(req, res){}).listen(8888);//建立服务器并监听端口var testUrl = 'http://localhost:8888/aaaa?id=1&name=2;var p = url.parse(testUrl);console.log(p.href); 取到的值是:'http://localhost:8888/aaaa?id=1&name=2;console.log(p.protocol); 取到的值是:http:console.log( p.hostname); 取到的值是:locahostconsole.log(p.host); 取到的值是:localhost:8888console.log(p.port); 取到的值是:8888console.log(p.path); 取到的值是:/aaaa?id=1&name=2;console.log(p.hash); 取到的值是:nullconsole.log(p.query); 取到的值是:id=1&name=2;console.log( p.pathname); 取到的值是:/aaaa |
更多免费学习资料可关注:itheimaGZ 获取