Computer Networking学习笔记[2]

HTTP

HTTP or HyperText Transfer Protocol is the protocol at the core of the web.

Objects

  • Web pages are objects that consist of other objects.
  • An object is simply a file like an HTML file, PNG file, MP3 file, etc.
  • Each object has a URL
  • The base object of a web page is often an HTML file that has references to other objects by making requests for them via their URL.

A URL, or Universal Resource Locator, is used to locate files that exist on servers. URLs consist of the following parts:

  • Protocol in use
  • The hostname of the server
  • The location of the file
  • Arguments to the file

It’s a client-server protocol that specifies how Web clients request Web pages from Web servers and how Web servers send them. Note that HTTP is a stateless protocol: servers do not store any information about clients by default. So if a client requests the same object multiple times in a row, the server would send it and would not know that the same client is requesting the same object repeatedly.

HTTP Requires Lower Layer Reliability

  • Application layer protocols rely on underlying transport layer protocols called UDP (User Datagram Protocol) and TCP (Transmission Control Protocol).

  • For now, all you need to know is that TCP ensures that messages are always delivered. Messages get delivered in the order that they are sent.

  • UDP does not ensure that messages get delivered. This means that some messages may get dropped and so never be received.

  • HTTP uses TCP as its underlying transport protocol so that messages are guaranteed to get delivered in order. This allows the application to function without having to build any extra reliability as it would’ve had to with UDP.

Request Messages

GET /path/to/file/index.html HTTP/1.1
Host: www.educative.io
Connection: close
User-agent: Mozilla/5.0
Accept-language: fr
Accept: text/html

it should be noted that,

  • HTTP messages are in plain ASCII text
  • Each line of the message ends with two control characters: a carriage return and a line feed: \r\n.
  • The last line of the message also ends with a carriage return and a line feed!
  • This particular message has 6 lines, but HTTP messages can have one or as many lines as needed.
  • The first line is called the request line while the rest are called header lines.

The Anatomy of an HTTP Request Line

The HTTP request line is followed by an HTTP header. We’ll look at the request line first. The request line consists of three parts:

  • Method
  • URL
  • Version
image.png

HTTP Methods

HTTP methods tell the server what to do. There are a lot of HTTP methods but we’ll study the most common ones: GET, POST, HEAD, PUT, or DELETE.
GET is the most common and requests data.

POST puts an object on the server.

This method is generally used when the client is not sure where the new data would reside. The server responds with the location of the object.
The data posted can be a message for a bulletin board, newsgroup, mailing list, a command, a web form, or an item to add to a database.
The POST method technically requests a page but that depends on what was entered.

HEAD is similar to the GET method except that the resource requested does not get sent in response. Only the HTTP headers are sent instead.

This is useful for quickly retrieving meta-information written in response headers, without having to transport the entire content. In other words, it’s useful to check with minimal traffic if a certain object still exists. This includes its meta-data, like the last modified date. The latter can be useful for caching.
This is also useful for testing and debugging.

PUT uploads an enclosed entity under a supplied URI. In other words, it puts data at a specific location. If the URI refers to an already existing resource, it’s replaced with the new one. If the URI does not point to an existing resource, then the server creates the resource with that URI.

DELETE deletes an object at a given URL.

你可能感兴趣的:(Computer Networking学习笔记[2])