node. JS (iii)--URL module

Source: Internet
Author: User

URL module:

URL: Uniform Resource Locator, emphasis on positioning

URI: Uniform Resource Identifier, emphasis on identity

A Web site is a URL, a specific symbol that describes which protocol to access a resource

URIs are more abstract, and a string format specification is a conceptual definition

In fact, URLs are a subset of URIs

There are three methods in this module

Url.parse (URLSTR, [parsequerystring], [Slashesdenotehost])

Resolves an address and parses it into an object

Url.format (Urlobj)

Format a URL object as a URL string

Url.resolve (from, to)

It is also used for parsing, stitching two parameters into a format that the browser can recognize

The following is used to demonstrate the URL module:

Url.parse (URLSTR, [parsequerystring], [Slashesdenotehost])

Entering the node environment, enter the URL

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/8E/F3/wKioL1jPzDmji2GnAAA8DyES64E899.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1jpzdmji2gnaaa8dyes64e899.jpg "/>

The components of the URL are as follows:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8E/F5/wKiom1jPzJPDssbLAABNLsYOS5o145.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jpzjpdssblaabnlsyos5o145.jpg "/>

Protbcol: The protocol used by the underlying is HTTP or FTP, etc.

Slashes: whether there is a double slash of the Protocol

Hash: Hashed value, Anchor point value

Search: Query string parameters

Query: Data sent to the HTTP protocol, usually in the form of a parameter string

Pathname: Access Resource path name

Path: Paths

Detailed analysis is as follows:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/8E/F3/wKioL1jPzmeDcYDtAACEFntjnPw408.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1jpzmedcydtaacefntjnpw408.jpg "/>

A second parameter:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/8E/F6/wKiom1jP0NaBQ8JFAACOpO5PiAE328.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jp0nabq8jfaacopo5piae328.jpg "/>

A third parameter:

There is a situation where you do not know the transport protocol of an address, but want to get the correct host

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/8E/F3/wKioL1jP0cXBHJlbAAC3U4wULoI932.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1jp0cxbhjlbaac3u4wuloi932.jpg "/>

Parameters can be passed on demand

Url.format (Urlobj)

To demonstrate the Format object

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/8E/F6/wKiom1jPz2aBYR3iAACL9-zQLxg353.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jpz2abyr3iaacl9-zqlxg353.jpg "/>

Url.resolve (from, to)

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/8E/F3/wKioL1jPz8_hrqJiAAAZ3I_HGMI881.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1jpz8_hrqjiaaaz3i_hgmi881.jpg "/>


URL module can be used as long as the receive path parameter that involves the network request is processed

Can parse out the components of a URL to identify the type of request and to determine how to access the data


This article is from the "It Rookie" blog, make sure to keep this source http://mazongfei.blog.51cto.com/3174958/1908561

node. JS (iii)--URL module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.