0012-每特教育螞蟻課堂深入理解http協(xié)議與12306搶票實(shí)現(xiàn)_第1頁(yè)
0012-每特教育螞蟻課堂深入理解http協(xié)議與12306搶票實(shí)現(xiàn)_第2頁(yè)
0012-每特教育螞蟻課堂深入理解http協(xié)議與12306搶票實(shí)現(xiàn)_第3頁(yè)
0012-每特教育螞蟻課堂深入理解http協(xié)議與12306搶票實(shí)現(xiàn)_第4頁(yè)
0012-每特教育螞蟻課堂深入理解http協(xié)議與12306搶票實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩12頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Http 一、Http 協(xié)議入httphttp 協(xié)議: 對(duì)瀏覽器客戶端 和 服務(wù)器端 之間二Http 一、Http 協(xié)議入httphttp 協(xié)議: 對(duì)瀏覽器客戶端 和 服務(wù)器端 之間二、查http 協(xié)議的工2)使用谷歌的http協(xié)議響應(yīng)(服務(wù)器-瀏覽器HTTP/1.1200Content-Length: 24Date:Fri,30Jan201501:54:57thisoGET /day09/ o HTTP/1.1 Host: localhost:8080User-Agent:Mozilla/5.0(WindowsNT6.1;WOW64;rv:35.0)Gecko/20100101Firefox

2、/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Encoding: gzip, deflate 四、Http3.1 GETo#http#請(qǐng)求資資源標(biāo)記符。四、Http3.1 GETo#http#請(qǐng)求資資源標(biāo)記符。o(/0/myweb/indx.html# T、HEAD、TRACE、PUT、CONNECT 常用的請(qǐng)求方式: TGEToHost:User-Agent:Mozilla/5.0(WindowsNT6.1;WOW64;rv:35.0)Gecko/20100101Fire

3、fox/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Encoding: gzip, deflate formaction=提交地址T formaction=提交地址T c)GET。T 3.2 Accept:- : - Host: localhost:8080User-Agent:Mozilla/5.0(WindowsNT6.1;WOW64;rv:35.0)Gecko/20100101Firefox/35.0 Accept: text/html,application/xht

4、ml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Encoding: gzip, deflateConnection:keep-Host: localhost:8080User-Agent:Mozilla/5.0(WindowsNT6.1;WOW64;rv:35.0)Gecko/20100101Firefox/35.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Encoding: gzip, deflateConnection:keep-3.

5、3 實(shí)體 3.4HttpServletRequest 3.3 實(shí)體 3.4HttpServletRequest 實(shí)體內(nèi)容3.5service doXX 方法區(qū)HttpSevlet類的源碼protectedvoidservice(HttpServletRequestreq,HttpServletResponse throwsServletException,IOExceptionAccept-Language:en-us,zh-If-Modified-Since: Tue, 11 Jul 2000 18:23:51 GMT- 當(dāng)前請(qǐng)求來(lái)自于哪里User-Agent:Mozilla/4.0comp

6、atibleMSIE5.5;WindowsNT- 瀏覽器保存Connection: close/Keep- 瀏覽器跟服務(wù)器連接狀態(tài)。close: Date:Tue11Jul200018:23:51- /得到請(qǐng)求方/得到請(qǐng)求方Stringmethod=if (method.equals(METHOD_GET) longlastModified=if(lastModified=-1)/servletdoesntsupportif-modified-since,no/togothroughfurtherexpensivelogic doGet(req, resp);elselongtryifModi

7、fiedSince = catch(IllegalArgumentExceptioniae)/ Invalid date header - proceed as if nifModifiedSince = -1;if(ifModifiedSince(lastModified/1000*1000)/Iftheservletmodtimeislater,call/Rounddowntothenearestsecondfora/AifModifiedSinceof-1willalwaysbeless maybeSetLastModified(resp, lastModified); doGet(re

8、q, resp);elseelseif long lastModified = doHead(req, resp);elseift(req,elseifdoPut(req,elseif案例時(shí)間 案例防1 2 :案例時(shí)間 案例防1 2 :)代碼elseifelseifelse/tthismeansNOservletsupports/methodwasrequested,anywhereonthisStringerrMsgObject errArgs = new Object1; errArgs0 = method;errMsg=MessageFormat.format(errMsg,3.8 傳遞

9、的請(qǐng)求參數(shù)如何GET3.8 傳遞的請(qǐng)求參數(shù)如何GETURIT TpublicclassImgFilterimplementsFilterpublicvoiddestroy()/TODOAuto-generatedmethodpublicvoiddoFilter(ServletRequestservletRequest,ServletResponse servletResponse, FilterChain filterChain)throwsIOException,ServletExceptionHttpServletRequest request = (HttpServletRequest)

10、 servletRequest; HttpServletResponseresponse=(HttpServletResponse)servletResponse; String referer = request.getHeader(referer);ln(referis+ if(referer=null| elsefilterChain.doFilter(request,publicvoidinit(FilterConfigarg0)throwsServletException/TODOAuto-generatedmethod。的 API: 取多個(gè)值的參數(shù)Http響應(yīng)#http 協(xié)議。的

11、API: 取多個(gè)值的參數(shù)Http響應(yīng)#http 協(xié)議#狀態(tài)碼: 服務(wù)器處理請(qǐng)求的結(jié)果(狀態(tài)200 #常見(jiàn)的響應(yīng) HTTP/1.1200Server: Apache-Coyote/1.1Content-Length: 24Date:Fri,30Jan201501:54:57thiso5.3HttpServletResponse對(duì) 5.3HttpServletResponse對(duì) 5.4 案例- 請(qǐng)求重定向resp.setHeader(Location,Server:apache: - : Content-Type: text/html; charset=GB2312Last-Modified: T

12、ue, 11 Jul 2000 18:23:51 GMTRefresh: 1;url=ition:attaent; filename=aaa.zip -表示告訴瀏覽器以:SS=Q0=5Lb_nQ; path=/searchExpires:1Cache-Controlno-cachePragma:no-Connection: close/Keep-Alive接 keep-alive:保存連接六、Https6.1.1http6.1.2https六、Https6.1.1http6.1.2https都知道 HTTPS 能夠加密信息,以免敏感信息被第級(jí)別較高的服務(wù)都會(huì)采用 HTTPS 協(xié)議??蛻舳嗽谑褂?/p>

13、HTTPS 方式與Web 服務(wù)器通信時(shí)有以下幾個(gè)步驟客戶使用https 的Web 服務(wù)器,要求與Web 服務(wù)器建立SSL 連接Web 服務(wù)器收到客戶端請(qǐng)求后,會(huì)信息Web SSL Web 服務(wù)器利用自己的私 1、https 協(xié)議需要到ca 申2、http 是超文本傳輸協(xié)議,信息是明文傳輸,https ssl 3、http https 804434、http 的連接很簡(jiǎn)單,是無(wú)狀態(tài)的;HTTPS SSL+HTTP 協(xié)議構(gòu)建的可進(jìn)行加密傳輸、認(rèn)證的網(wǎng)絡(luò)協(xié)議,比 http 協(xié)議安全。6.1.3https雖然說(shuō)HTTPS6.1.3https雖然說(shuō)HTTPS 有很大的優(yōu)勢(shì),但其相對(duì)來(lái)說(shuō),還是存HTTPS

14、 50%10% 20% HTTPS HTTP 高效,會(huì)增加數(shù)據(jù)開(kāi)銷和功耗,甚至已有的安全措施也會(huì)因此而受通常需要綁定IP,不能在同一IP 上綁定多,IPv4 資源不可能支撐這個(gè)消耗HTTPS 協(xié)議的加密范圍也比較有限,在到什么作用。最關(guān)鍵的的信用鏈體系并不安全,特別是在某些國(guó)家可以控制CA 的情七、http 請(qǐng)求工7.1 客戶端模七、http 請(qǐng)求工7.1 客戶端模擬http請(qǐng)求工tmen(谷歌插件)、RestC 7.2 服務(wù)器模擬http請(qǐng)求工httpc nt、httpCient* 發(fā)t請(qǐng)本地應(yīng)用并根據(jù)傳遞參數(shù)不同返回不同結(jié)publict()/ 創(chuàng)建默認(rèn)的nt實(shí)例ntnt=/創(chuàng)建tt=Lis

15、tformparams=newArrayList(); ameValuePair(type, house); UrlEncodedFormEntity uefEntity;tryuefEntity=newUrlEncodedFormEntity(formparams,UTF-8); ln(executing request + httpCloseableHttpResponse response = httpctry HttpEntityentity=response.getEntity(); if (entity != null) ln(Responsecontent:+ EntityUti

16、ls.toString(entity, UTF-8);finallycatchntProtocolException catch(UnsupportedEncodingExceptioncatch(UnsupportedEncodingException catch(IOException finally/ 關(guān)閉連接資 catch(IOException *發(fā)送get請(qǐng)publicvoidget()nt httpcnt = HttpCtry 創(chuàng)建HttpGet httpget = new HttpGet(htln(executingrequest+httpget.getURI();執(zhí)行g(shù)et請(qǐng)

17、求CloseableHttpResponse response = httpctry HttpEntityentity=打印響應(yīng)狀if (entity != null) / 打印響應(yīng)內(nèi)容長(zhǎng)ln(Responsecontentlength:+ ln(Responsecontent:+ finallyajax跨域?qū)崙?zhàn)解決方 。annotajax跨域?qū)崙?zhàn)解決方 。annotload type:ype:url : data : userName=余勝軍&userAge=19,s:function(msg) catch(ParseException catch(IOException finally/

18、關(guān)閉連接資 catch(IOException 使 response 添加header *); 支持使 response 添加header *); 支持有前端代碼后端代碼publicclassFromUserServletextendsHttpServletprotectedvoiddoGet(HttpServletRequestreq,HttpServletResponseresp)throws ServletException, IOException t(req,protected void dot(HttpServletRequestreq,HttpServletResponseresp)throws ServletException, IOException /s-Control-Allow-Origin,ty

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論