简单介绍基于WEB开发的HTTP协议
简单介绍基于WEB开发的HTTP协议今天搜索socket时找到一篇文章<基于Java的web服务器工作原理>,却在里面看到了部分介绍HTTP协议的,虽然简单,但是读完之后,还是对HTTP有一点新的理解,所以摘录了一下(部分内容经过笔者更改).
HTTP(The Hypertext Transfer Protocol) 是一种让 Web 服务器与浏览器(客户端)通过 Internet 发送与接收数据的协议。它是一个请求、响应协议.客户端发出一个请求,服务器响应这个请求。HTTP 运用可靠的 TCP 连接,通常用的 TCP 80 端口。它的第一个版本是 HTTP/0.9 ,然后被 HTTP/1.0 取代。当前的版本是 HTTP/1.1 ,由RFC2616(.pdf) 定义。
本节主要对应 HTTP 1.1 ,足够使你充分理解由 Web 服务器程序发出的消息。如果你对更加详细的知识有兴趣,可以参考 RFC2616 。
在 HTTP 中,客户端总是通过建立一个连接,并发送一个 HTTP 请求来发起一个事务。服务器不能主动去与客户端联系,也不能给客户端发出一个回叫连接。客户端与服务器端都可以提前中断一个连接。例如,当用一个浏览器下载一个文件时,你可以通过点击“停止”键来中断文件的下载,关闭与服务器的 HTTP 连接。
HTTP 请求
一个 HTTP 请求包含三个部分:
Method-URI-Protocol/Version方法-地址-版本
Request header请求头
Entity body请求实体
下面是一个 HTTP 请求实例
<blockquote style="margin-right: 0px;"><div style="padding-right: 5.4pt; padding-left: 5.4pt; background: #e6e6e6; padding-bottom: 4px; width: 95%; padding-top: 4px;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif POST/servlet/default.jspHTTP/1.1
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Accept:text/plain;text/html
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Accept-Language:en-gb
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Connection:Keep-Alive
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Host:localhost
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Referer:http://localhost/ch8/SendDetails.htm
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif User-Agent:Mozilla/4.0(compatible;MSIE4.01;Windows98)
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Content-Length:33
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Content-Type:application/x-www-form-urlencoded
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif Accept-Encoding:gzip,deflate
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif LastName=Franks&FirstName=Michael
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif
页:
[1]