zoukankan      html  css  js  c++  java
  • node.js在windows下的学习笔记(10)---URL模块

    1.parse函数的作用是解析url,返回一个json格式的数组

    url.parse('http://www.zjut.edu.cn');
    { protocol: 'http:',
      slashes: true,
      auth: null,
      host: 'www.zjut.edu.cn',
      port: null,
      hostname: 'www.zjut.edu.cn',
      hash: null,
      search: null,
      query: null,
      pathname: '/',
      path: '/',
      href: 'http://www.zjut.edu.cn/' }
    > 

    2.parse函数的第二个参数是布尔类型,当参数为true时,会将查询条件也解析成json格式的对象。

    url.parse('http://www.baidu.com?page=1',true);
    { protocol: 'http:',
      slashes: true,
      auth: null,
      host: 'www.baidu.com',
      port: null,
      hostname: 'www.baidu.com',
      hash: null,
      search: '?page=1',
      query: { page: '1' },
      pathname: '/',
      path: '/?page=1',
      href: 'http://www.baidu.com/?page=1' }
    > 

    3.parse函数的第三个参数也是布尔类型的,当参数为true,解析时会将url的"//"和第一个"/"之间的部分解析为主机名

    url.parse('http://www.baidu.com/news',false,true);
    { protocol: 'http:',
      slashes: true,
      auth: null,
      host: 'www.baidu.com',
      port: null,
      hostname: 'www.baidu.com',
      hash: null,
      search: null,
      query: null,
      pathname: '/news',
      path: '/news',
      href: 'http://www.baidu.com/news' }
    > 

    4.format函数的作用与parse相反,它的参数是一个JSON对象,返回一个组装好的url地址

    url.format({
    protocol: 'http:',
    hostname:'www.baidu.com',
    port:'80',
    pathname :'/news',
    query:{page:1}
    });
    'http://www.baidu.com:80/news?page=1'

    5.resolve函数的参数是两个路径,第一个路径是开始的路径或者说当前路径,第二个则是想要去往的路径,返回值是一个组装好的url

    url.resolve('http://example.com/', '/one')
    'http://example.com/one'
  • 相关阅读:
    Android面向切面编程(AOP)(转)
    Android性能优化
    Android 性能分析之TraceView使用(应用耗时分析)
    Lint检查选项
    Android Chromium WebView Crash
    Could not get unknown property 'assembleRelease' for project ':app' of type org.gradle.api.Project.
    Android studio gradle 无法获取 pom文件
    android 7.0 因为file://引起的FileUriExposedException异常
    Android双系统实现
    git 安装 和 基本操作
  • 原文地址:https://www.cnblogs.com/michaeljunlove/p/3975060.html
Copyright © 2011-2022 走看看