• 【nodejs】URL模块


    new URL(input, [base])

    base验证input的origin是否符合预期

    let myUrl = new URL('test/index.html', 'https://example.com');
    // https://example.com/test/index.html
    
    myUrl = new URL('http://Example.com/test/index.html', 'https://example.com');
    // http://example.com/test/index.html

    URL格式

    URL {
      href: 'http://example.com/test/index.html',
      origin: 'http://example.com',
      protocol: 'http:',
      username: '',
      password: '',
      host: 'example.com',
      hostname: 'example.com',
      port: '',
      pathname: '/test/index.html',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    }

    URLSearchParams

    创建

    let params;
    params = new URLSearchParams('user=abc&query=xyz');
    params = new URLSearchParams('?user=abc&query=xyz');
    params = new URLSearchParams({ user: 'abc', query: ['first', 'second'] });
    params = new URLSearchParams([
      ['user', 'abc'],
      ['query', 'first'],
      ['query', 'second'],
    ]);

    api

    params.append('xxx', 123);
    params.delete('user');
    params.forEach((v, key) => {
      console.log(v, key);
    });
    params.get('user');
    params.getAll('query');
    params.has('user');
    params.keys();
    // 如果存在任何名称为 name 的预先存在的名称-值对,则将第一个此类对的值设置为 value 并删除所有其他名称。 如果没有,则将名称-值对追加到查询字符串。
    params.set('user', 'def');
    params.sort();
    params.values();
    params.toString();
  • 相关阅读:
    ASP.NET在MVC控制器中获取Form表单值的方法
    MVC中几种常用ActionResult
    EF 配置MySQL
    HTTP 错误 403.6
    26个Jquery使用小技巧(转)
    Win2008R2配置WebDeploy(转)
    IIS快捷方式
    发布你的程序包到Nuget
    PostgreSQL recovery.conf恢复配置
    PostgreSQL 9.5 高可用、负载均衡和复制
  • 原文地址:https://www.cnblogs.com/zhoulixue/p/15391969.html
Copyright © 2020-2023  润新知