HTTP协议详解

这几天要努力学习基础知识,在总结php curl的用法和ajax的基础的时候发现要好好总结一下http,在维基百科上把http协议好好看了看 http协议是www的基础,所以也肯定是web开发的最基础的东西,总结写在下面,有不太清楚的同学可以看看。

定义:超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议。所有的WWW文件都必须遵守这个标准。

工作流程:
HTTP是一个客户端和服务器端请求和应答的标准(TCP)。客户端是终端用户,服务器端是网站。通过使用Web浏览器、网络爬虫或者其它的工具,客户端发起一个到服务器上指定端口(默认端口为80)的HTTP请求。(我们称这个客户端)叫用户代理(user agent)。应答的服务器上存储着(一些)资源,比如HTML文件和图像。(我们称)这个应答服务器为源服务器(origin server)

http

curl http过程


构成:
HTTP有两个关键部分:一个是请求 Request(客户端),一个是响应Response(服务器端)

Request Method:HTTP defines nine methods (sometimes referred to as “verbs”) indicating the desired action to be performed on the identified resource.HTTP请求总共有九种方法,包括(OPTIONS、GET、HEAD、POST、PUT、DELETE、TRACE)
详细的信息 参看
http://en.wikipedia.org/wiki/HTTP#Request_methods
POST和GET的区别请察看我原来写的日志http://www.vikingmute.com/archives/100

HTTP Headers:HTTP header fields are components of the message header of requests and responses in the Hypertext Transfer Protocol (HTTP). They define the operating parameters of an HTTP transaction.HTTP头信息是HTTP请求和回应中附带的描述性的信息。他们定义了HTTP交互中的操作参数。
Headers分为Request Headers和Response Headers两个的区别 下面两个个举一个例子。

http headers

HTTP headers

请看上面的图 这是wiki百科的请求和响应headers,举其中的两个例子
Host: The domain name of the server (for virtual hosting), mandatory since HTTP/1.1 :Host: en.wikipedia.org

Content-Type:The mime type of this content : Content-Type: text/html; charset=utf-8

所有Headers的参考列表,请看http://en.wikipedia.org/wiki/List_of_HTTP_headers

Status codes:In HTTP/1.0 and since, the first line of the HTTP response is called the status line and includes a numeric status code (such as “404″) and a textual reason phrase (such as “Not Found”). 在HTTP中,HTTP响应的第一行被称作状态行,包括一个状态码(比如404)和一个文字原因短语(比如“not found”)
比如说: HTTP/1.1 302 Found

所有的状态码列表请参考:http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

大体上就是这么多了,找这些资料 阅读和总结花了我大约2个多小时,累死了 不过也值了,搞清楚就最好了~

如果您想更深入的了解一些http的其他知识请看下面的参考

HTTP compression(HTTP压缩):http://en.wikipedia.org/wiki/HTTP_compression

HTTPS(HTTP Secure):http://en.wikipedia.org/wiki/HTTP_Secure

HTTP Cookie:http://en.wikipedia.org/wiki/HTTP_cookie

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

以新浪微博帐号登录