zoukankan      html  css  js  c++  java
  • Node.js核心模块-url

    引入

    const url = require('url')

    url.parse(urlString[, parseQueryString[, slashesDenoteHost]])

    • urlString:需要编译的url字符串
    • parseQueryString:布尔类型,默认为false。如果为真,则query属性返回parse之后的对象
    const obj = url.parse('http://localhost:3010/post?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA')
    console.log(obj)
    /*
    Url {
        protocol: 'http:',
        slashes: true,
        auth: null,
        host: 'localhost:3010',
        port: '3010',
        hostname: 'localhost',
        hash: null,
        search: '?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA',
        query: 'name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA',
        pathname: '/post',
        path: '/post?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA',
        href: 'http://localhost:3010/post?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA' }
     */

    当将parseQuerayaString设置为true时

    const obj = url.parse('http://localhost:3010/post?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA', true)
    console.log(obj)
    /*
    Url {
      protocol: 'http:',
      slashes: true,
      auth: null,
      host: 'localhost:3010',
      port: '3010',
      hostname: 'localhost',
      hash: null,
      search: '?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA',
      query: { name: '1234', message: '特为前提其他人' },
      pathname: '/post',
      path: '/post?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA',
      href: 'http://localhost:3010/post?name=1234&message=%E7%89%B9%E4%B8%BA%E5%89%8D%E6%8F%90%E5%85%B6%E4%BB%96%E4%BA%BA' }
     */

    打印结果中的query属性值是不一样的

  • 相关阅读:
    NYOJ 91 阶乘之和
    NYOJ 47 过河问题
    NYOJ 12 喷水装置(二)
    NYOJ 78 圈水池(凸包问题)
    NYOJ 523 亡命逃窜( bfs )
    NYOJ 564 最优对称路径(湖南省第七届大学生计算机程序设计竞赛)
    NYOJ 491 幸运三角形(bitset)
    排列组合 C(n,k)= C(n1)+C(n1,k1) 对应于杨辉三角
    Android (服务Service)
    Android (界面编程#5ProgressDialog)
  • 原文地址:https://www.cnblogs.com/lianglanlan/p/12378192.html
Copyright © 2011-2022 走看看