HTTP协议总结

理论:html

  1. 支持客户/服务器模式。java

  2. 简单快速:客户向服务器请求服务时,只需传送请求方法和路径。请求方法经常使用的有GET、HEAD、POST。每种方法规定了客户与服务器联系的类型不一样。因为HTTP协议简单,使得HTTP服务器的程序规模小,于是通讯速度很快。服务器

  3. 灵活:HTTP容许传输任意类型的数据对象。正在传输的类型由Content-Type加以标记。app

  4. 无链接:无链接的含义是限制每次链接只处理一个请求。服务器处理完客户的请求,并收到客户的应答后,即断开链接。采用这种方式能够节省传输时间。jsp

  5. 无状态:HTTP协议是无状态协议。无状态是指协议对于事务处理没有记忆能力。缺乏状态意味着若是后续处理须要前面的信息,则它必须重传,这样可能致使每次链接传送的数据量增大。另外一方面,在服务器不须要先前信息时它的应答就较快。ide

实践:post

http请求测试

eg:POST /reg.jsp HTTP/ (CRLF)
Accept:image/gif,image/x-xbit,... (CRLF)
...
HOST:www.guet.edu.cn (CRLF)
Content-Length:22 (CRLF)
Connection:Keep-Alive (CRLF)
Cache-Control:no-cache (CRLF)
(CRLF)         //该CRLF表示消息报头已经结束,在此以前为消息报头
user=jeffrey&pwd=1234  //此行如下为提交的数据ui

 

样本:url

基本get请求

GET /testupload/file_upload_javabean_form1.jsp?test=11123 HTTP/1.1
Accept: */*
Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; WOW64; Trident/6.0)
Accept-Encoding: gzip, deflate
Host: 127.0.0.1:1111
Connection: Keep-Alive
Cookie: JSESSIONID=1rc5wzqgboec02hogbehpjs88

HTTP/1.1 200 OK
Date: Tue, 20 May 2014 15:04:19 GMT
Content-Type: text/html;charset=UTF-8
Content-Length: 876
Server: Jetty(8.0.4.v20111024)

<!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=gb2312">
  <title>测试</title>
 </head>
 <body>
  <h1 align="center">测试</h1>
  <FORM NAME="form1" METHOD="POST" ACTION="file_upload_javabean_do1.jsp">
    <table width="80%" border="0" align="center" >
   <tr> 
     <td height="30" width="50%" align="right">测试</td>
     <td height="30" width="50%" align="left"><input type="input" name="data" size="30" value="111"></td>
   </tr>  
   <tr> 
     <td colspan="2" height="30" align="center">
     <input type="submit" name="Sub" value="测试">
     &nbsp;&nbsp;
     <input type="reset" name="Res" value="重置">
    </td>
   </tr>
    </table>
  </FORM>
 </body>
</html>

 基本post请求

POST /testupload/file_upload_javabean_do1.jsp HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://127.0.0.1:1111/testupload/file_upload_javabean_form1.jsp?test=11123
Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; WOW64; Trident/6.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: 127.0.0.1:1111
Content-Length: 32
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=1rc5wzqgboec02hogbehpjs88
 
data=4321&Sub=%E4%B8%8A%E4%BC%A0

  
HTTP/1.1 200 OK
Date: Tue, 20 May 2014 15:02:20 GMT
Content-Type: text/html;charset=UTF-8
Content-Length: 290
Server: Jetty(8.0.4.v20111024)
 
<!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=gb2312">
  <title>测试</title>
 </head>
 <body>
 
 
 <div>4321</div>
 </body>
</html>

post上传文件

POST /testupload/file_upload_javabean_do.jsp HTTP/1.1
Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Referer: http://127.0.0.1:1111/testupload/file_upload_javabean_form.jsp
Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; WOW64; Trident/6.0)
Content-Type: multipart/form-data; boundary=---------------------------7de776203f0
Accept-Encoding: gzip, deflate
Host: 127.0.0.1:1111
Content-Length: 280
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=1qnwmkj0juw6w1epld6xbloicx
 
-----------------------------7de776203f0
Content-Disposition: form-data; name="file"; filename="111.txt"
Content-Type: text/plain
12345
-----------------------------7de776203f0
Content-Disposition: form-data; name="Sub"
上传
-----------------------------7de776203f0--

  
HTTP/1.1 200 OK
Date: Tue, 20 May 2014 14:47:06 GMT
Set-Cookie: JSESSIONID=1rc5wzqgboec02hogbehpjs88;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/plain;charset=gb2312
Content-Length: 335
Server: Jetty(8.0.4.v20111024)
 
<!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=gb2312">
  <title>上传文件</title>
 </head>
 <body>
 <h1 align=center>文件 <font color=red>111.txt</font> 上传成功!</h1>
 </body>
</html>
相关文章
相关标签/搜索