1.http请求:
一个http请求一般包括三部分:
- 请求方法-统一的资源标识符(URL)-协议/版本
- 请求头
- 实体
//请求方法-统一的资源标识符(URL)-协议/版本
POST /examples/defalut.jsp HTTP/1.1
//请求头
//浏览器支持格式
Accept:text/plain;text/html
//浏览器支持的语言
Accept-Language: en-gb
//指定被请求资源的Internet主机和端口号
Host: localHost
//浏览器信息
User-Agent: Mozilla4.0(compatible;MSIE 4.01;Windows 98)
Content-Length:33
Content-Type: application/x-www/form-urlencoded
Accept=Encoding:gzip,deflate
//请求实体,请求头和请求实体间有一空行
lastname=Frank&firstname=Michael
2.http响应
一个http响应一般包括三部分:
- 协议-状态码-描述
- 响应头
- 响应实体段
//协议-状态码-描述
HTTP/1.1 200 OK
//响应头
Server: MIcrosoft-IIS/4.0
Date:Mon,5 Jan 2004 13:13:12 GMT
Content-Type:text/html
Last-Modified:Mon,5 Jan 2004 13:13:12 GMT
Content-Length:112
//响应实体段,响应头和响应实体之间需要有一空行
<html>
<head>
<title>http响应示例</title>
</head>
<body>
Welcome!
</body>
<//html>