阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js http2 request.url

      Node.js http2 request.url

      新增于: v8.4.0

      • < string>

      Request URL string. This contains only the URL that is present in the actual HTTP request. If the request is:

      GET /status?name=ryan HTTP/1.1\r\n
      Accept: text/plain\r\n
      \r\n
      

      Then request.url will be:

      '/status?name=ryan'
      

      To parse the url into its parts require(‘url’).parse(request.url) can be used:

      $ node
      > require('url').parse('/status?name=ryan')
      Url {
        protocol: null,
        slashes: null,
        auth: null,
        host: null,
        port: null,
        hostname: null,
        hash: null,
        search: '?name=ryan',
        query: 'name=ryan',
        pathname: '/status',
        path: '/status?name=ryan',
        href: '/status?name=ryan' }
      

      To extract the parameters from the query string, the require(‘querystring’).parse function can be used, or true can be passed as the second argument to require(‘url’).parse.

      $ node
      > require('url').parse('/status?name=ryan', true)
      Url {
        protocol: null,
        slashes: null,
        auth: null,
        host: null,
        port: null,
        hostname: null,
        hash: null,
        search: '?name=ryan',
        query: { name: 'ryan' },
        pathname: '/status',
        path: '/status?name=ryan',
        href: '/status?name=ryan' }
      

      更多内容请参考:Node.js HTTP2,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录