理論:html
支持客戶/服務器模式。java
簡單快速:客戶向服務器請求服務時,只需傳送請求方法和路徑。請求方法經常使用的有GET、HEAD、POST。每種方法規定了客戶與服務器聯繫的類型不一樣。因爲HTTP協議簡單,使得HTTP服務器的程序規模小,於是通訊速度很快。服務器
靈活:HTTP容許傳輸任意類型的數據對象。正在傳輸的類型由Content-Type加以標記。app
無鏈接:無鏈接的含義是限制每次鏈接只處理一個請求。服務器處理完客戶的請求,並收到客戶的應答後,即斷開鏈接。採用這種方式能夠節省傳輸時間。jsp
無狀態: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="測試"> <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>