Http 简明教程

HTTP - Overview

超文本传输协议(HTTP)是用于分布式、协作、超媒体信息系统的应用程序级协议。自 1990 年以来,它是万维网(即互联网)数据通信的基础。HTTP 是通用且无状态的协议,它还可以用于其他用途,同时使用其请求方法、错误代码和标题的扩展程序。

The Hypertext Transfer Protocol (HTTP) is an application-level protocol for distributed, collaborative, hypermedia information systems. This is the foundation for data communication for the World Wide Web (i.e. internet) since 1990. HTTP is a generic and stateless protocol which can be used for other purposes as well using extensions of its request methods, error codes, and headers.

基本来说,HTTP 是一个基于 TCP/IP 的通信协议,用于在万维网上交付数据(HTML 文件、图像文件、查询结果等)。默认端口是 TCP 80,但也可以使用其他端口。它为计算机提供了一种标准化的方法相互通信。HTTP 规范指定了如何构造和发送客户端请求数据到服务器,以及服务器如何响应这些请求。

Basically, HTTP is a TCP/IP based communication protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests.

Basic Features

有三个基本特性让 HTTP 成为一个简单而强大的协议:

There are three basic features that make HTTP a simple but powerful protocol:

  1. HTTP is connectionless: The HTTP client, i.e., a browser initiates an HTTP request and after a request is made, the client waits for the response. The server processes the request and sends a response back after which client disconnect the connection. So client and server knows about each other during current request and response only. Further requests are made on new connection like client and server are new to each other.

  2. HTTP is media independent: It means, any type of data can be sent by HTTP as long as both the client and the server know how to handle the data content. It is required for the client as well as the server to specify the content type using appropriate MIME-type.

  3. HTTP is stateless: As mentioned above, HTTP is connectionless and it is a direct result of HTTP being a stateless protocol. The server and client are aware of each other only during a current request. Afterwards, both of them forget about each other. Due to this nature of the protocol, neither the client nor the browser can retain information between different requests across the web pages.

Basic Architecture

下图显示了一个 Web 应用程序非常基本的架构,并描述了 HTTP 的位置:

The following diagram shows a very basic architecture of a web application and depicts where HTTP sits:

cgiarch

HTTP 协议是一个基于客户端/服务器架构的请求/响应协议,其中 Web 浏览器、机器人和搜索引擎等充当 HTTP 客户端,而 Web 服务器充当服务器。

The HTTP protocol is a request/response protocol based on the client/server based architecture where web browsers, robots and search engines, etc. act like HTTP clients, and the Web server acts as a server.

Client

HTTP 客户端以请求方法、URI 和协议版本的形式将请求发送到服务器,然后是包含请求修饰符、客户端信息和可能通过 TCP/IP 连接传递的主体内容的 MIME 类似消息。

The HTTP client sends a request to the server in the form of a request method, URI, and protocol version, followed by a MIME-like message containing request modifiers, client information, and possible body content over a TCP/IP connection.

Server

HTTP 服务器使用状态行(包括消息的协议版本和成功或错误代码)来响应,然后是包含服务器信息、实体元信息和可能的实体主体内容的 MIME 类似消息。

The HTTP server responds with a status line, including the message’s protocol version and a success or error code, followed by a MIME-like message containing server information, entity meta information, and possible entity-body content.