HTTP Study Notes-URL and resource, http Study Notes url

Source: Internet
Author: User
Tags ftp protocol

HTTP Study Notes-URL and resource, http Study Notes url
What is URL?

All things have a standard things, bus line number, plane flight number, personal ID card number, you take a taxi, tell the driver I want to go to Shi Pai, then he can understand what you mean. URL is the standardized name of Internet resources. The URL points to an electronic information clip, telling you where they are located and how to interact with them.

URI

The Uniform Resource Identifier (URI) is a type of more common Resource Identifier, including URL and URN. A URL identifies a resource by describing its location, and a URL identifies the resource by its name, regardless of its current location.

URL syntax

Most of the URLs we encounter (for example"Http://soccer.hupu.com/germany") Is composed of three parts: Scheme (http), host (soccer.hupu.com), path (/germany ). The URL syntax varies with the scheme! The URL Syntax of most URL schemes is based on a general format consisting of nine parts:

<Scheme>: // <user >:< password >@< host >:< port >/< path >;< params>? <Query >#< frag>

However, almost no URL contains all these components.

Solution

First, let's look at what the solution is.

The scheme is actually to specify how to access the primary identifier of a specified resource. It will tell the application responsible for URL parsing what protocol should be used. We usually use http (which is ignored by most browsers), https (secure version of http), ftp, and so on.

The solution name is case-insensitive, that is"Http://www.google.com"And"HTTP: www.google.com"It is equivalent (you can try it in your browser ).

Host and Port

To access resources on the Internet, we need to know which machine is loaded with the resource and where it can be found, this is the information provided by the host and port in the URL. We can use the host name (www.hupu.com) or IP address (112.90.32.241) to represent the host name. The port component identifies the port on which the server is listening. The default http port is 80, and the default https port is 443.

Username and password

The user and password components usually appear in the ftp protocol.

Ftp://ftp.prep.ai.mit.edu/pub/gnuIn this example, there is no user or password component. When the URL scheme requires a user name and password, it inserts anonymous as your user name and sends a default password.

Ftp: // anonymous@ftp.prep.ai.mit .edu/pug/gnuThis example shows the specified username anonymous. Character @ separates the user and password components from other parts of the URL.

Ftp: // anonymous: my_password@ftp.prep.ai.mit.edu/pub/gnuThe user name and password are specified.

Path

Just like the file path in a PC. Each path has its own parameters.

Parameters

The parameter component in the URL is a list of name-value pairs separated by the character. They provide applications with additional information needed to access resources.Ftp://ftp.prep.ai.mit.edu/pub/gnu;type=d

Can you see what is the parameter name and value in the above example?

Query

Let's use an example to illustrateHttp: // bbs: scoccer.com/15630262.html? Item = 123. In this example? The content on the right is the query component. We use the query component to narrow the requested resource range.

We generally use the "name/value" method to query. Name-value pairs are separated:Http: // bbs: scoccer.com/15630262.html? Item = 123 & color = blue.

Fragment

The URL supports the use of the fragment component to represent an internal fragment of a resource, such as a specific image and section in an HTML document. For example:

Http: // bbs: scoccer.com/15630262.html?robben

* The HTTP server processes the entire object instead of the object fragment. After the whole resource is returned from the server, the client browser displays the fragment you are interested in.URL shortcuts

There are two URL Methods: absolute and relative. We generally see absolute URLs. The relative URL is a convenient scaling method of the URL, which is a URL segment or a small part. I should have seen all those who have experience in development. Let's take a look at the next HTML document.

<HTML><HEAD><TITLE>Joe's Tools</TITLE></HEAD><BODY><H1>Tools Page</H1><H2>Hammers</H2><P>Joe's Hardware Online has the largest selection of <A HREF="./hammers.html">hammers</A> on the earth.</P><H2><A NAME=drills></A>Drills</H2><P>Joe's Hardware has a complete line of cordless and corded drills,as well as the latest in plutonium-powered atomic drills, for thosebig around the house jobs.</P> ...</BODY></HTML>

./Hammers.html is a relative path.
Since it is a relative path, it must have a relative object. This object is the so-called basic URL. In this example, the basic URL is http://www.joes-hardware.com/tools.com. So how does the basic URL come from.

1. Display and provide in the resource. For example, an HTML document may contain a tag that defines the basic URL <BASE>

2. encapsulate the basic URL of the resource. If no base URL is explicitly specified, you can use the URL of the resource to which it belongs.

3. There is no basic URL. It usually means that this is an absolute URL. Of course, this URL may be incomplete.

So how can we convert a relative URL to an absolute URL? Let's look at the figure below.

We use the algorithm in the graph for./hanmmers.html.

1) path is./hammmers.html, the basic URL is http://www.joes-hardware.com/tools.html

2) The scheme is empty and inherits the scheme of the basic URL (HTTP)

3) The component is empty and inherits the host and port components.

4) Merge the relative URL with the inherited component: http://www.joes-hardware.com/hammmers.html.

Automatic extension of URL host name extension

In the HTTP authority Guide, if we enter yahoo in the address bar, www. And. com will be automatically inserted in the host name. However, I have not found the corresponding example yet.

History extension

This is a lot of what we use in our daily life. Through the websites we visit, the browser will automatically provide us with some complete options for us to choose.

Future

We already know that the URL provides the location of the resource we need. Its disadvantage is that once the resource is removed, we cannot locate the resource through the URL. Our solution officially mentioned above URN.

URN (uniform resource name) Unified resource name. The idea is to introduce another intermediate layer in the Process of resource search. Through an intermediate Resource Locator, the server registers and tracks the actual URL of the resource, in this way, no matter where our resource is moved, as long as it is not deleted, the locator can redirect this resource to the actual URL of the requested resource. However, it takes some time to replace the URL, which is not an urgent issue in Web development.

Related Article

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.