Url
- Url.parse (urlstr[, parsequerystring][, Slashesdenotehost])
- Url.format (Urlobj)
- Url.resolve (from, to)
Specific address: http://nodejs.cn/api/url.html
3 Modes of reference
C:\Documents and Settings\administrator\webstormprojects\untitled3>node
Enter node environment first
> URL
{parse: [Function:urlparse],
Resolve: [Function:urlresolve],
Resolveobject: [Function:urlresolveobject],
Format: [Function:urlformat],
URL: [Function:url]}
Call URL
Parse Parse:
- Url.parse (urlstr[, parsequerystring][, Slashesdenotehost])
> Url.parse (' http://www.imooc.com/video/6710 ')
Build Item:
{protocol: ' http: ',
Slashes:true,
Auth:null,
Host: ' Www.imooc.com ',
Port:null,
Hostname: ' www.imooc.com ',
Hash:null,
Search:null,
Query:null,
Pathname: '/video/6710 ',
Path: '/video/6710 ',
HREF: ' http://www.imooc.com/video/6710 '}
Format parsing: The information you give generates a URL
> Url.format ({protocol: ' http: ',
... slashes:true,
... auth:null,
... host: ' Www.imooc.com ',
... port:null,
... hostname: ' www.imooc.com ',
... hash:null,
... search:null,
... query:null,
... pathname: '/video/6710 ',
... path: '/video/6710 ',
... href: ' http://www.imooc.com/video/6710 '}
... )
Build item: ' http://www.imooc.com/video/6710 '
Resolve parsing
> url.resolve (' http://imooc.com/', '/course/list ')
Build item: ' Http://imooc.com/course/list '
Application of Parse
> Url.parse (' Http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1 ')
{protocol: ' http: ',
Slashes:true,
Auth:null,
Host: ' imooc.com:8080 ',
Port: ' 8080 ',
Hostname: ' imooc.com ',
Hash: ' #dloor1 ',
Search: '? From=scott&&course=node ',
query: ' From=scott&&course=node ',
Pathname: '/curse/list ',
Path: '/curse/list?from=scott&&course=node ',
HREF: ' Http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1 '}
> Url.parse (' Http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1 ',true)
{protocol: ' http: ',
Slashes:true,
Auth:null,
Host: ' imooc.com:8080 ',
Port: ' 8080 ',
Hostname: ' imooc.com ',
Hash: ' #dloor1 ',
Search: '? From=scott&&course=node ',
query: {from: ' Scott ', ': ', ' Course: ' node '}, //query is parsed as an object
Pathname: '/curse/list ',
Path: '/curse/list?from=scott&&course=node ',
HREF: ' Http://imooc.com:8080/curse/list?from=scott&&course=node#dloor1 '}
Compare it to each other and see what's different.
> Url.parse ('//imooc.com/curse/liast ', true)
{protocol:null,
Slashes:null,
Auth:null,
Host:null,
Port:null,
Hostname:null,
Hash:null,
Search: ",
Query: {},
Pathname: '//imooc.com/curse/liast ',
Path: '//imooc.com/curse/liast ',
HREF: '//imooc.com/curse/liast '}
> Url.parse ('//imooc.com/curse/liast ', True,true)
{protocol:null,
Slashes:true,
Auth:null,
host: ' Imooc.com ',
Port:null,
Hostname: ' imooc.com ',
Hash:null,
Search: ",
Query: {},
Pathname: '/curse/liast ',
Path: '/curse/liast ',
HREF: '//imooc.com/curse/liast '}
Protocol: Protocol
Slashes: whether there is a double slash of the Protocol
Auth
Host: Domain/IP address
Port: Ports
Hostname: Host Name
Hash: Target an anchor point
Search: Query string parameters
Query: A parameter string that is sent to http with an argument = number branch Open
Pathname: Access Resource path name
Path: Paths
HREF: Hypertext link
node. JS URL Module