[关闭]
@Wangww0925 2019-08-07T08:03:07.000000Z 字数 447 阅读 188

req.url() 与 url.parse(req.url).pathname 的区别

NodeJs


例子

  1. var http = require("http");
  2. var url = require("url");
  3. http.createServer((req,res)=>{
  4. console.log(req.url);
  5. console.log(url.parse(req.url).pathname);
  6. }).listen(8081);

访问 http://localhost:8081/detail?fff , 结果为

  1. /detail?fff
  2. /detail

结论:

req.url() 带参数

url.parse(req.url).pathname 不带参数

req.url() 与 url.parse(req.url).path 一致

作者 wendy
2019 年 1月 21日


参考文献

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注