HTTP的请求格式:请求格式中的四个部分信息:请求行信息、请求头信息、空白行信息、请求体信息、
POST /day04-http/index.html HTTP/1.1 //请求行信息
Accept: text/html, application/xhtml+xml, */* //请求头信息
Referer: http://localhost:8080/day04-http/index.html
Accept-Language: zh-CN
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: localhost:8080
Content-Length: 10
Connection: Keep-Alive
Cache-Control: no-cache
//空白行信息::分隔响应头信息和响应体信息
name=fdghd //请求体信息
Accept-Language: zh-CN
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: localhost:8080
Content-Length: 10
Connection: Keep-Alive
Cache-Control: no-cache
//空白行信息::分隔响应头信息和响应体信息
name=fdghd //请求体信息
一、请求行信息:
POST /day04-http/index.html HTTP/1.1
请求行信息分三部分
1)请求方式:POST
get:该方式会以?和&符号的方式显式的显示在地址栏上,因此该方式是明文传输的,并且传输的资源有限。
post:该方式提交的数据会存储在请求体中,但也是明码的,但可以传输很大的数据信息
2)请求资源:/day04-http/index.html
/网站名/具体的资源名
如果是get方式则是: /网站名/具体的资源名?name=shfj
3)请求协议:HTTP/1.1
请求协议/版本号
HTTP1.0和HTTP1.1的区别:
1.0是早期的版本:该版本中会给每一次浏览器的请求都建立一次TCP/IP连接(比较安全)比较耗时
1.1该版本是后期的,如果浏览器核武器需要保持连接,那么服务器就和浏览器
二、请求头信息
它是浏览器发送给服务器的,主要是通知服务器一些事情
Accept: text/html, application/xhtml+xml, */* //通知服务器,浏览器可以接受的数据类型
Referer: http://localhost:8080/day04-http/index.html //通知服务器,浏览器请求时的引用路径
Accept-Language: zh-CN //通知服务器,浏览器可以接受的语言种类
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) //通知服务器,用户上网的代理软件是谁
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate //通知服务器,浏览器可接收的资源种类
Host: localhost:8080 //指定请求资源的主机名
Content-Length: 10
Connection: Keep-Alive
Cache-Control: no-cache
Accept-Language: zh-CN //通知服务器,浏览器可以接受的语言种类
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0) //通知服务器,用户上网的代理软件是谁
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate //通知服务器,浏览器可接收的资源种类
Host: localhost:8080 //指定请求资源的主机名
Content-Length: 10
Connection: Keep-Alive
Cache-Control: no-cache
HTTP相应格式:分为响应行信息、响应头信息、空白行信息、响应体信息
HTTP/1.1 200 OK 响应行信息
Server: Apache-Coyote/1.1 // 响应头信息
Accept-Ranges: bytes
ETag: W/"386-1362317486015"
Last-Modified: Sun, 03 Mar 2013 13:31:26 GMT
Content-Type: text/html
Content-Length: 386
Date: Sun, 03 Mar 2013 13:32:27 GMT
// 空白行信息
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> // 响应体信息
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="" method="post">
Name:<input type="text" name="name"/>
<input type="submit" value="submit" />
</form>
</body>
</html>
Server: Apache-Coyote/1.1 // 响应头信息
Accept-Ranges: bytes
ETag: W/"386-1362317486015"
Last-Modified: Sun, 03 Mar 2013 13:31:26 GMT
Content-Type: text/html
Content-Length: 386
Date: Sun, 03 Mar 2013 13:32:27 GMT
// 空白行信息
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> // 响应体信息
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="" method="post">
Name:<input type="text" name="name"/>
<input type="submit" value="submit" />
</form>
</body>
</html>
一、相应行信息:HTTP/1.1 200 OK
1)响应协议/版本
2)相应状态码
0~600
常用的状态码:
200 响应成功
304 需要浏览器继续发送请求来细化原来的请求
404 资源不存在
500 服务器发生异常了
3)响应状态码的说明信息
二、响应头信息
Server: Apache-Coyote/1.1 //处理请求的服务器名
Accept-Ranges: bytesETag: W/"425-1362322259204"
Last-Modified: Sun, 03 Mar 2013 14:50:59 GMT
Content-Type: text/html
Content-Length: 425
Date: Sun, 03 Mar 2013 14:51:57 GMT