HTTP超文本传输协议,是WWW上应用的最多的协议。了解和掌握HTTP协议是对程序人员的基本要求。
转载请注明出处 http://www.cnblogs.com/zrtqsk/p/3746891.html ,谢谢
一、HTTP介绍
HTTP是一个基于请求/响应模式的、无状态的协议。即,浏览器与服务端连接之后,浏览器向服务器发送一个请求,服务器返回响应信息之后,双方的链接就被关闭。我们要知道,应用层的HTTP要使用传输层的TCP协议来完成。而TCP协议是通过“3次握手”建立连接,是面向连接的协议。默认情况下,浏览器与Web服务器上80端口监听的服务器程序建立TCP连接。
HTTP1.0是典型的请求/响应模式。为了减少服务器的开销,HTTP默认有“持续连接”的机制。通过这种机制,客户端发送请求得到响应后,连接不会马上关闭,可以继续发送请求,还可以流水线发送多个请求、而不用等待每一个响应的到来。
二、URI和URL
URI(统一资源标识符)纯粹是一种符号结构,用于指定构成Web资源的字符串的各个不同部分。而URL(统一资源定位符)是一种特殊的URI,包含了用于查找某个资源的足够信息。
URI是一种语义上的抽象概念,可以是绝对的,也可以是相对的,而URL则必须提供足够的信息来定位,所以,是绝对的,而通常说的relative URL,则是针对另一个absolute URL,本质上还是绝对的。
三、HTTP请求
格式如图:(CRLF表示回车符+换行符,不同颜色之间用空格隔开)
SWTBvUx9yhGDOUPxCMAaCqT8xsP7EIIo45SvmIMF8pzSPIuuDju8cJpjjFGUOE8yYMyvGnFlJsYZgohDMSQoRgiEEYyaYd8g0BDPmzMrXKbIQTIyCeYF0IRjd6/SH5AvBGAjmXTr+P+8iGDPBrHqDAnv9zCoEE0/BDHZwCCYSwXQecWgIJiLBnKhwbggmQsH8QAgm8YIZ4oAQTKyC+chJIZioBfOeY0IwsQnmzR9WvfnDaueFYJItmFND6k+9mEYNUUMw8RXM/HQJwcRZMFPTLgQTd8GMTd8QjJUE02DbEEyiBXPU/iGYhArmpM1DMAkXzJqxP6wZZ//GqiEY6wlmqA1DMEkXzAL7hGCSKpgMG4ZgUiCY0jXjSteMt0/KA0YwdhLMsIYSy4ZgEAyCsb5gMk9es2AIxkqC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BgEYzHBEBElKgSDYBAMgolaMEREdgjBIBgEk9aCISJybggGwSAY2wiGiIgiDsEgGASTHMEQEVGKQzAIBsEQEVE6hWAQjG0FQ0REZBaCQTAWEgwREVE8QzAIpm+CISIisksIJm0EQ0RERGYhmKQLhoiIiJKXgwWjICZUo4iIiMgOmbyaKy/3thHM8wXvDyiYPaBw9sDDvY554cgHg4/MUzRDRERETmvw0XmDj8xTSKDa5fCcAYWzBxTMfr7g/cQKRkHME3lT++Vl9MtTHaNQpv++rKf3ZT+dT0RERBRr+7L778tS4KLaJS+jX17GE3lTFb5ELZieR4/C3oBhGIZhGCbRE9YkwdtgGIZhGIZhrD8IhmEYhmEY+w2CYRiGYRjGfoNgGIZhGIax3yAYhmEYhmHsNwiGYRiGYRj7DYJhGIZhGMZ+8/8B+o+MlHErVikAAAAASUVORK5CYII=" alt="" />
第一行叫做请求行。所以我们可以说HTTP请求由请求行、消息报头、请求正文组成。
1、请求行
如上,请求行以一个方法符号开头,空格之后,一个请求URI,再空格,然后一个HTTP版本,最后一个回车换行。
其中请求方法有如下几种:
XLS9pKNrakQhv3Dw5YutBKhKITjqrMjEbNstK+T/x62q9rl9Vtav71+6O6LHek11qcVrm0oTs96H4JB1Tyd5K39r09K3ZAHowWLZ8B5Hqxry9LybAUSB60WC4KQQtw7XC8nZb5Wh5QpZ5Vrf39/v56XyfL69WbbVKz1Xbl06k1MKWXzqdJaDsb1iGqjGtTLWwMx5dM1U3NWsxUJqLU7g6XaQzVcfLlqqe5he+0sd0bajWqT9F35y7s5O2596sxH7R7oCvHphZ0U4qWXH1IhrpUvBbUtCvH2RN5tMS56iuOt+94GX+ZuRP+zHWxxAvmt7YCDamgnT9VncJ+tVVYCjiux3Dp0Z7ytyMIK3c0QaqbT6aAFgy7s9x1i+Pf9ARWinbpeTqrvFCjEOxB5t4Wx34nq5Zb9qPe/XeinpAZVc24jCns1W9XAH1RrVEsOdjc/esStelKqZ3UPuzsZzFl1GLlul/sPEtSEfmW6c7g6n5T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7uTlshrG7S3qrXlh/LpjW2nFtvmlpIJLH2NljaqIhqCVYV8ddY7FW7b91khKuDHJaTrTOuRlRLsyLG9zN+uMGjbwedR9TfsXqh9WRaqAl0KzoRQgrxJROnVu/mqdpciHFnSdCy66FdW48Is/bTycEZER5ExBrfZ2QfrKCWvYPIqk1bNfYrCsa1Eo44VFep2aoR2+jWtvvFRk4zePTqE+jTPXfrWC0D51CsQLud/luDQkhOrd5gx4lPOXQz8duE2i++GK+6n15767t1uoZfqZp5cEMcrGQcA7WiQx2WZRA8mm4JzkL1kfiiPT9Wkmo4K3R3D50QqhNrxDIYnqh4aacMCiHJVi8AgEVIIT5nIlu9AAAWKIQkW70AABYohCRbvQAAFiiEJFu9AAAWKIQkW70AABYhhfgxE9nqBQCwQCEk2eoFALAIKcQPmchWLwCABQohyVYvAIAFCiHJVi8AgEVIIb7PRLZ6AQAsUAhJtnoBACxCCvFdJrLVCwBgYf6d6qenp83n73//+2kmfve73x07BQCAk+D3v//9oAXDZ2lFAwAA4En8yrTRjd1gLWtZy1rWfmVrD/YdYp/siUtc4hKXuCcYl+8QrGUta1nLWh3+OwQAAOj8f5sLLPssxyrNAAAAAElFTkSuQmCC" alt="" />
我们在浏览器地址栏直接输入地址的时候,采用的就是GET方法。
HEAD方法一般用于测试超链接的有效性,因为它只是请求响应消息的报头。消息报头后面会讲。
(HTTP协议中,请求方法必须全部大写)
2、请求正文
类似name=XXX&pwd=XXXX的内容
四、HTTP响应
格式与HTTP请求类似,如图:
Ante9/vyE7t2J9Gjis7tX3v++1ZE9q3vxVsl2H7z4w8eP713LI3f7z41pGfyYGNOXzx1ZwLIw6cM7TLoNzZg4/MHXps3ivHPyVSGnps3uAjcwflzo6OXZ6qzX/6+rGnrx97hhyQ8r1+qjb/iatHw7LLgfSOQ9M7Ds0gJzW940B6eHb5+Z2jl8bllZOjGnv0Uph2GV6wYGThopGFi0aRU1N+AIYXLIiDXX6ipKv/dvlQLYeSMe/3t692Ga+UT0laXvn4/tplMT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2IaK+hF2wC3bBLtglJnYhokSHXbALdsEuzrYLESVh2AW7YBfsYnu7EBFhF+yCXbCLZexCRBSrsAt2wS7YJQK7EBHZIeyCXbBLktqFiMi5YRfsgl1sYBciIgo77IJdsEus7UJERAkOu2AXR9uFiIiSKOyCXWxoFyIiolBhF+xiCbsQERFFM+yCXfpqFyIiIruEXZLALkRERBQq7BJHuxAREVH8cqRdFL6YNZKIiIjsUIhnc+Xp3gZ2eSFn5sCcWQNzZw067BPMS0c+GnxkruIYIiIiclqDj84dfGSuQgJVLYdnD8ydNTBn1gs5M2NlF4UvT2SlDMhKHZClCkZBzNP70p/Zl/FMNhEREVFf25fx9L50hSyqWrJSB2SlPpGVosAlArs8fPTIbFeGYRiGYZi4jZlJDNZdGIZhGIZhLDvYhWEYhmEYOw12YRiGYRjGToNdGIZhGIax02AXhmEYhmHsNNiFYRiGYRg7DXZhGIZhGMZOg10YhmEYhrHT/H97yKdmbtcuvQAAAABJRU5ErkJggg==" alt="" />
第一行叫做状态行。所以我们可以说HTTP响应由状态行、消息报头、响应正文组成。
1、状态行
如上,状态行由一个HTTP版本,空格后,一个状态码,再空格,一个状态码的文本描述,最后一个回车换行构成。
状态代码有3位数字组成,状态描述给出了状态代码简短的描述。状态码第一个数字定义了响应的类别,有五种可能取值:
1xx : 指示信息--表示请求已接收,继续处理
2xx : 成功--表示请求已被成功接收、理解、接受
3xx : 重定向--要完成请求必须进行更进一步的操作
4xx : 客户端错误--请求有语法错误或请求无法实现
5xx : 服务器端错误--服务器未能实现合法的请求
全部取值如下:
消息报头下面会讲。
2、响应正文
所谓响应正文,就是服务器返回的资源的内容。即整个HTML文件。
五、消息报头
HTTP请求和HTTP响应都有消息报头。而消息报头是由众多报头域组成。每一个报头域都由名字+“:”+空格组成,消息报头域的名字是大小写无关的。
HTTP消息报头包括普通报头、请求报头、响应报头和实体报头。
1、普通报头:
在普通报头中,有少数报头域用于所有的请求和响应消息,但并不用于被传输的实体,只用于传输的消息。
普通报头包括:
常见的普通报头:
1)Cache-Control
Cache-Control用于指定缓存指令,缓存指令是单向的(响应中出现的缓存指令在请求中未必会出现),且是独立的(一个消息的缓存指令不会影响另一个消息处理的缓存机制),HTTP1.0使用的类似的报头域为Pragma。
请求时的缓存指令包括:no-cache(用于指示请求或响应消息不能缓存)、no-store、max-age、max-stale、min-fresh、only-if-cached;
响应时的缓存指令包括:public、private、no-cache、no-store、no-transform、must-revalidate、proxy-revalidate、max-age、s-maxage.
2)Date
Date普通报头域表示消息产生的日期和时间
3)Connection
Connection普通报头域允许发送指定连接的选项。例如指定连接是连续,或者指定“close”选项,通知服务器,在响应完成后,关闭连接
2、请求报头
请求报头允许客户端向服务器端传递请求的附加信息以及客户端自身的信息。
请求报头包括:
AWTsoIuA7b5DkzYz38zp2VfBevauvZAupFvVvY521m263y3vybecIVDMGwJhMzJPuEy5Atkzt3h6HxhAtlUVaq7Gv+I0XEpFZRtfVsAfWi3i28jPXwvTkBqrYelEXZvcq+jPU4j7Mk/72rauvZAupFvVuw383c4y2fyXoKIWU9rP5YxvJZl1+o1VMIKevJuVEAcBpgPVvZ3XreDtyfR1mUjQHr2UrV1rMF1It6t4AZKZQ4pvWgLMruVRbWowTGegCgwHqUQKsHZVGWAutR4pjWswXUi3q3sNV6wGqOYD0oi7J7lYX17AbGesArs8B6fgBp0OpB2ZctO2M9X758eQfl+fLlS9EwlwD1ot4tzFjPkV0TZVEWZestO2M9AABQArR6UBZlUXaHsgVbPWfto6Je1It6t4NWD8qiLMruUPb/AeCHKZ6hCwQdAAAAAElFTkSuQmCC" alt="" />
常见的请求报头:
1)Accept
Accept请求报头域用于指定客户端接受哪些类型的信息。
2)Accept-Charset
Accept-Charset请求报头域用于指定客户端接受的字符集。如果在请求消息中没有设置这个域,缺省是任何字符集都可以接受。
3)Accept-Encoding
Accept-Encoding请求报头域类似于Accept,但是它是用于指定可接受的内容编码。如果请求消息中没有设置这个域服务器假定客户端对各种内容编码都可以接受。
4)Accept-Language
Accept-Language请求报头域类似于Accept,但是它是用于指定一种自然语言如果请求消息中没有设置这个报头域,服务器假定客户端对各种语言都可以接受。
5)Authorization
Authorization请求报头域主要用于证明客户端有权查看某个资源。当浏览器访问一个页面时,如果收到服务器的响应代码为401(未授权),可以发送一个包含Authorization请求报头域的请求,要求服务器对其进行验证。
6)Host
发送请求时,该报头域是必需的。Host请求报头域主要用于指定被请求资源的Internet主机和端口号,它通常从HTTP URL中提取出来的。
7)User-Agent
User-Agent请求报头域允许客户端将它的操作系统、浏览器和其它属性告诉服务器。不过,这个报头域不是必需的,如果我们自己编写一个浏览器,不使用User-Agent请求报头域,那么服务器端就
无法得知我们的信息了。
3、响应报头
响应报头允许服务器传递不能放在状态行中的附加响应信息,以及关于服务器的信息和对Request-URI所标识的资源进行下一步访问的信息。
响应报头包括:
PSPP5+fnx8fH+/g6dkwKd80B1XjaUr6+vP0COr68vNtGhsyzQOQ+WzpGGcgPrWAwAdBYBOucBhlIYJHoeoHMeNhvKMJeLAEiBRM8DdM7Dos593w8eMnxAD0UYJHoeoHMeFnVOO+S5HxepAEDnMNA5D1I6w1AikQoAdA4DnfMgpTMMJRKpAEDnMNA5D1I6ixrKSTVN210LBeDatY2FOifbm1QAKk308xBK+Q1v5Tg6M/nZNI0688tziy+ls6ChXLu2UUo16iQTAB/XrmWdwlme9KSQCkD5RGfQoUxnyGs5js6+vF3fICVSOssZyrVrG3Ua/hQJgI/VhpI0QlIBKJ/oLoNuRfNbcxydYSibAqCd5KTmYc8kkzMCYRfez8pedu3atuvIYn5FvU2/oeht6zWvXduobtre3JXRu1Adt/644DYc6txB3W2iO2jZzsrs4a1TRhapRC+vc4ShuEl790XhUaR0ljIUYiPk4yDJeMyzXuxC89OYyIN481ptd9025BkXkFNDD4SuXat9ZG46fyL7Zn6b75D3l+g2plazo6xVRhapRC+vMztXQhPWTmAuafkoCCCls5ChGGfUSTXjsMe5xtlCedTULYyl4z9ChrJmXmvaOD0D+IvyFDzut9HD3Heie+QxFNiijCxSiV5e54eGPJO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46f/hrB7+NU9yex+8HDesW/KdHTJbbixkn0Jknjykt++kdIahRCIVAOgcpi6dnf+PwDzO5zUU57bA4oOX3k2xDwu5cPf42Z3CUIojFQDoHKYmne0HJflnuMMuYDdYelDTvynvI9/hpxDZne7FUEAeQwE5dL52rVWrYjynza/0Z3ahrwG7l/Cm2FfJ6p90u/HvuGZ3uhoYSmFgKHnIoDNb+2Y6Zecvr13bzC4wndv8KU2Whr2D35T55mr7h5DqPYbLcDuV0xmGkhYYSh7S6+x5tfx0AuuRRNt1inrL/DXbRziRBy+db03r8WxqGns5i9ruRA2JtHF2KqczDCUtMJQ8QOc8pDIUEM2mRAfRQOc8bDaU0qXdDwib6KV/1AGBznlYNpS3t7cXAADYwtvbG28oPoan9OPAulgX6z7buguGAgAA60EPBetiXawrtm7CHsojB4P9Yr/Y7x73+z9hdzAWabbMggAAAABJRU5ErkJggg==" alt="" />
常见的实体报头:
1)Location
Location响应报头域用于重定向接受者到一个新的位置。Location响应报头域常用在更换域名的时候。
2)Server
Server响应报头域包含了服务器用来处理请求的软件信息。与User-Agent请求报头域是相对应的。
3)WWW-Authenticate
WWW-Authenticate响应报头域必须被包含在401(未授权的)响应消息中,客户端收到401响应消息时候,并发送Authorization报头域请求服务器对其进行验证时,服务端响应报头就包含该报头域。
4、实体报头
请求和响应消息都可以传送一个实体。一个实体由实体报头域和实体正文组成,但并不是说实体报头域和实体正文要在一起发送,可以只发送实体报头域。实体报头定义了关于实体正文(eg:有无实体正文)和请求所标识的资源的元信息。
实体报头包括:
常见的实体报头:
1)Content-Encoding
Content-Encoding实体报头域被用作媒体类型的修饰符,它的值指示了已经被应用到实体正文的附加内容的编码,因而要获得Content-Type报头域中所引用的媒体类型,必须采用相应的解码机制。Content-Encoding主要用于记录文档的压缩方法。
2)Content-Language
Content-Language实体报头域描述了资源所用的自然语言。没有设置该域则认为实体内容将提供给所有的语言
阅读者。
3)Content-Length
Content-Length实体报头域用于指明实体正文的长度,以字节方式存储的十进制数字来表示。即一个数字字符占一个字节,用其对应的ASCII码来存储传输。
4)Content-Type
Content-Type实体报头域用语指明发送给接收者的实体正文的媒体类型。
5)Expires
Expires实体报头域给出响应过期的日期和时间。为了让代理服务器或浏览器在一段时间以后更新缓存中(再次访问曾访问过的页面时,直接从缓存中加载,缩短响应时间和降低服务器负载)的页面,我们可以使用Expires实体报头域指定页面过期的时间。
6)Last-Modified
Last-Modified实体报头域用于指示资源的最后修改日期和时间。
六、长度限制
1、URL长度限制
1)HTTP协议中没有对URL的长度进行限制,class="top11">但是Web服务器和浏览器对URI都有自己的长度限制。服务器一般是通过控制http请求头的长度来进行限制的。tomcat的请求配置参数为maxHttpHeaderSize。
2)浏览器的限制
每种浏览器也会对url的长度有所限制,下面是几种常见浏览器的url长度限制:(单位:字符) IE : 2803ASCII字符 Firefox : 65536ASCII字符 Chrome : 8182ASCII字符 Safari : 80000ASCII字符 Opera : 190000ASCII字符 对于get请求,在url的长度限制范围之内,请求的参数个数没有限制。2. Post数据的长度限制
Post数据的长度限制与url长度限制类似,也是在Http协议中没有规定长度限制,长度限制可以在服务器端配置最大http请求头长度的方式来实现。3、Cookie的长度限制
1)浏览器所允许的每个域下的最大cookie数目
IE :原先为20个,后来升级为50个
Firefox: 50个
Opera:30个
Chrome:180个
Safari:无限制
当Cookie数超过限制数时浏览器的行为:IE和Opera会采用LRU算法将老的不常使用的Cookie清除掉,Firefox的行为是随机踢出某些Cookie的值。当然无论怎样的策略,还是尽量不要让Cookie数目超过浏览器所允许的范围。
2) 浏览器所允许的每个Cookie的最大长度
Firefox和Safari : 4079字节
Opera : 4096字节
IE : 4095字节
(3) 服务器中Http请求头长度的限制。
Cookie会被附在每次http请求头中传递给服务器,因此还会受到服务器请求头长度的影响。
4. Html5 LocalStorage的长度限制
Html5提供了本地存储机制来供Web应用在客户端存储数据,尽管这个并不属于Http协议的一部分,但是随着Html5的流行,我们可能需要越来越多使用LocalStorage,甚至当它普及的时候跟它打交道就会同今天我们跟Cookie打交道一样多。
对于LocalStorage的长度限制,同Cookie的限制类似,也是浏览器针对域来限制,只不过cookie限制的是个数,LocalStorage限制的是长度:
Firefox\Chrome\Opera : 5MB
IE : 10MB
参考引用:http://blog.sina.com.cn/s/blog_5f5716580100lq5x.html
http://www.php100.com/html/itnews/it/2012/1216/11778.html
《Java Web开发详解》-孙鑫