国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Http協(xié)議入門

番茄西紅柿 / 3528人閱讀

[在此處輸入文章標題]

 

 

1 web

 web入門

                   1)web服務軟件作用: 把本地資源共享給外部訪問

                   2)tomcat服務器基本操作       :

                                     啟動:  %tomcat%/bin/startup.bat

                                     關(guān)閉: %tomcat%/bin/shutdown.bat

 

                                     訪問tomcat主頁:

                                                        http://localhost:8080

                   3)web應用目錄結(jié)構(gòu)

                                     |- WebRoot   根目錄

                                               |-靜態(tài)資源(html+css+javascript+images+xml)  可以直接被瀏覽器訪問到的

                                               |-WEB-INF                                  不可以直接被瀏覽器訪問到

                                                        |-classes     存放class字節(jié)碼文件

                                                        |-lib         存放jar包文件

                                                        web.xml      web應用的配置文件,配置servlet

                                    

                   4)Servlet技術(shù): 用java語言開發(fā)動態(tài)資源的技術(shù)

                                     開發(fā)一個Servlet程序的步驟:

                                                        1)創(chuàng)建一個java類,繼承HttpServlet類

                                                        2)重寫HttpServlet類的doGet方法

                                                        3)把寫好的servlet程序交給tomcat服務器運行!!!!

                                                                 3.1 把編譯好的servlet的class文件拷貝到tomcat的一個web應用中。(web應用                                                                                             的WEB-INF/classes目錄下)             
                                                                 3.2 在當前web應用的web.xml文件中配置servlet

                                                                                   

                                                                                   

                                                                                             HelloServlet

                                                                                             gz.itcast.HelloServlet

                                                                                   

                                                                                   

                                                                                   

                                                                                             HelloServlet

                                                                                              /hello

                                                                                   

                                                        4)訪問servlet

                                                                           http://localhost:8080/myweb/hello

 

今天的目標: http協(xié)議

 

2 Http協(xié)議入門

                     2.1 什么是http協(xié)議

                                     http協(xié)議: 對瀏覽器客戶端 和  服務器端 之間數(shù)據(jù)傳輸?shù)母袷揭?guī)范

 

                     2.2 查看http協(xié)議的工具

                                     1)使用火狐的firebug插件(右鍵->firebug->網(wǎng)絡)

                                     2)使用谷歌的“審查元素”

                                     3)使用系統(tǒng)自帶的telnet工具(遠程訪問工具)                                 

                                                        a)telnet localhost 8080      訪問tomcat服務器

                                                        b)ctrl+]     回車          可以看到回顯

                                                        c)輸入請求內(nèi)容

                                                                

GET /day09/hello HTTP/1.1

Host: localhost:8080

                                                        d)回車,即可查看到服務器響應信息。

 

                     2.3 http協(xié)議內(nèi)容

                           

請求(瀏覽器-》服務器)

GET /day09/hello HTTP/1.1

Host: localhost:8080

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3

Accept-Encoding: gzip, deflate

Connection: keep-alive

 

        

響應(服務器-》瀏覽器)

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Content-Length: 24

Date: Fri, 30 Jan 2015 01:54:57 GMT

 

this is hello servlet!!!

 

3 Http請求

GET /day09/hello HTTP/1.1               -請求行

Host: localhost:8080                    --請求頭(多個key-value對象)

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3

Accept-Encoding: gzip, deflate

Connection: keep-alive

                                    --一個空行

name=eric&password=123456             --(可選)實體內(nèi)容

 

              3.1 請求行

                            GET /day09/hello HTTP/1.1    

              #http協(xié)議版本

                   http1.0:當前瀏覽器客戶端與服務器端建立連接之后,只能發(fā)送一次請求,一次請求之后連接關(guān)閉。

                   http1.1:當前瀏覽器客戶端與服務器端建立連接之后,可以在一次連接中發(fā)送多次請求。(基本都使用1.1)

 

              #請求資源

                                     URL:  統(tǒng)一資源定位符。http://localhost:8080/day09/testImg.html。只能定位互聯(lián)網(wǎng)資源。是URI                                                          的子集。

                                     URI: 統(tǒng)一資源標記符。/day09/hello。用于標記任何資源。可以是本地文件系統(tǒng),局域網(wǎng)的資源(//192.168.14.10/myweb/index.html),                                                    可以是互聯(lián)網(wǎng)。

              #請求方式

                            常見的請求方式: GET 、 POST、 HEAD、 TRACE、 PUT、 CONNECT 、DELETE    

 

                            常用的請求方式: GET  和 POST 

 

                            表單提交:

                                    

   

 

                                    

 

                            GET   vs  POST 區(qū)別

 

                            1)GET方式提交

                                               a)地址欄(URI)會跟上參數(shù)數(shù)據(jù)。以?開頭,多個參數(shù)之間以&分割。

GET /day09/testMethod.html?name=eric&password=123456 HTTP/1.1

Host: localhost:8080

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3

Accept-Encoding: gzip, deflate

Referer: http://localhost:8080/day09/testMethod.html

Connection: keep-alive

 

                                               b)GET提交參數(shù)數(shù)據(jù)有限制,不超過1KB。

                                               c)GET方式不適合提交敏感密碼。

                                               d)注意: 瀏覽器直接訪問的請求,默認提交方式是GET方式

                            2)POST方式提交

                                     a)參數(shù)不會跟著URI后面。參數(shù)而是跟在請求的實體內(nèi)容中。沒有?開頭,多個參數(shù)之間以&分割。

POST /day09/testMethod.html HTTP/1.1

Host: localhost:8080

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3

Accept-Encoding: gzip, deflate

Referer: http://localhost:8080/day09/testMethod.html

Connection: keep-alive

 

name=eric&password=123456

 

                                               b)POST提交的參數(shù)數(shù)據(jù)沒有限制。

                                               c)POST方式提交敏感數(shù)據(jù)。

              3.2 請求頭

Accept: text/html,image/*      -- 瀏覽器接受的數(shù)據(jù)類型

Accept-Charset: ISO-8859-1     -- 瀏覽器接受的編碼格式

Accept-Encoding: gzip,compress  --瀏覽器接受的數(shù)據(jù)壓縮格式

Accept-Language: en-us,zh-       --瀏覽器接受的語言

Host: www.it315.org:80          --(必須的)當前請求訪問的目標地址(主機:端口)

If-Modified-Since: Tue, 11 Jul 2000 18:23:51 GMT  --瀏覽器最后的緩存時間

Referer: http://www.it315.org/index.jsp      -- 當前請求來自于哪里

User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)  --瀏覽器類型

Cookie:name=eric                     -- 瀏覽器保存的cookie信息

Connection: close/Keep-Alive            -- 瀏覽器跟服務器連接狀態(tài)。close: 連接關(guān)閉  keep-alive:保存連接。

Date: Tue, 11 Jul 2000 18:23:51 GMT      -- 請求發(fā)出的時間

 

              3.3 實體內(nèi)容

                                     只有POST提交的參數(shù)會放到實體內(nèi)容中

 

              3.4 HttpServletRequest對象

                            HttpServletRequest對象作用是用于獲取請求數(shù)據(jù)。

 

                                        核心的API:

                                               請求行:

                                                        request.getMethod();   請求方式

                                                        request.getRequetURI()   / request.getRequetURL()   請求資源

                                                        request.getProtocol()   請求http協(xié)議版本

                                              

                                               請求頭:

                                                        request.getHeader("名稱")   根據(jù)請求頭獲取請求值

                                                        request.getHeaderNames()    獲取所有的請求頭名稱

 

                                               實體內(nèi)容:

                                                        request.getInputStream()   獲取實體內(nèi)容數(shù)據(jù)

              3.5 service 和 doXX方法區(qū)別

 

                           

HttpSevlet類的源碼:

protected void service(HttpServletRequest req, HttpServletResponse resp)

        throws ServletException, IOException {

       //得到請求方式

        String method = req.getMethod();

 

        if (method.equals(METHOD_GET)) {

            long lastModified = getLastModified(req);

            if (lastModified == -1) {

                // servlet doesnt support if-modified-since, no reason

                // to go through further expensive logic

                doGet(req, resp);

            } else {

                long ifModifiedSince;

                try {

                    ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE);

                } catch (IllegalArgumentException iae) {

                    // Invalid date header - proceed as if none was set

                    ifModifiedSince = -1;

                }

                if (ifModifiedSince < (lastModified / 1000 * 1000)) {

                    // If the servlet mod time is later, call doGet()

                    // Round down to the nearest second for a proper compare

                    // A ifModifiedSince of -1 will always be less

                    maybeSetLastModified(resp, lastModified);

                    doGet(req, resp);

                } else {

                    resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);

                }

            }

 

        } else if (method.equals(METHOD_HEAD)) {

            long lastModified = getLastModified(req);

            maybeSetLastModified(resp, lastModified);

            doHead(req, resp);

 

        } else if (method.equals(METHOD_POST)) {

            doPost(req, resp);

           

        } else if (method.equals(METHOD_PUT)) {

            doPut(req, resp);       

           

        } else if (method.equals(METHOD_DELETE)) {

            doDelete(req, resp);

           

        } else if (method.equals(METHOD_OPTIONS)) {

            doOptions(req,resp);

           

        } else if (method.equals(METHOD_TRACE)) {

            doTrace(req,resp);

           

        } else {

            //

            // Note that this means NO servlet supports whatever

            // method was requested, anywhere on this server.

            //

 

            String errMsg = lStrings.getString("http.method_not_implemented");

            Object[] errArgs = new Object[1];

            errArgs[0] = method;

            errMsg = MessageFormat.format(errMsg, errArgs);

           

            resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, errMsg);

        }

    }

 

              3.6 案例-獲取瀏覽器的類型(user-agent)

              3.7 案例- 防止非法鏈接(referer)

第1次                      CSDN/51CTO    ->   頁面(點擊下載)   -> 彈出廣告頁面(點擊此處下載) -> 開始下載 

第2次         直接點擊此處下載  ->  轉(zhuǎn)回廣告頁面  ->  開始下載

 

                                     非法鏈接:                                                          

                                                        1)直接訪問下載的資源

                                                        2)不是從廣告頁面過來的鏈接

 

                                     referer: 當前請求來自于哪里。

              3.8 傳遞的請求參數(shù)如何獲取          

                             GET方式: 參數(shù)放在URI后面

                             POST方式: 參數(shù)放在實體內(nèi)容中

 

                            獲取GET方式參數(shù):

                                               request.getQueryString();

                            獲取POST方式參數(shù):

                                               request.getInputStream();

 

                            問題:但是以上兩種不通用,而且獲取到的參數(shù)還需要進一步地解析。

                            所以可以使用統(tǒng)一方便的獲取參數(shù)的方式:

                                    

                                    核心的API:

                                     request.getParameter("參數(shù)名");  根據(jù)參數(shù)名獲取參數(shù)值(注意,只能獲取一個值的參數(shù))

                                     request.getParameterValue("參數(shù)名“);根據(jù)參數(shù)名獲取參數(shù)值(可以獲取多個值的參數(shù))

 

                                     request.getParameterNames();   獲取所有參數(shù)名稱列表  

              3.9 請求參數(shù)編碼問題

                                     修改POST方式參數(shù)編碼:

                                                        request.setCharacterEncoding("utf-8");

                                     修改GET方式參數(shù)編碼:

                                                        手動解碼:String name = new String(name.getBytes("iso-8859-1"),"utf-8");

4 Http響應

HTTP/1.1 200 OK                --響應行

Server: Apache-Coyote/1.1         --響應頭(key-vaule)

Content-Length: 24

Date: Fri, 30 Jan 2015 01:54:57 GMT

                                   --一個空行

this is hello servlet!!!                  --實體內(nèi)容

 

                     4.1 響應行

                   #http協(xié)議版本

                      #狀態(tài)碼: 服務器處理請求的結(jié)果(狀態(tài))

                                               常見的狀態(tài):

                                                        200 :  表示請求處理完成并完美返回

                                                        302:   表示請求需要進一步細化。
                                                        404:   表示客戶訪問的資源找不到。

                                                        500:   表示服務器的資源發(fā)送錯誤。(服務器內(nèi)部錯誤)

                     #狀態(tài)描述        

      4.2 常見的響應頭

Location: http://www.it315.org/index.jsp   -表示重定向的地址,該頭和302的狀態(tài)碼一起使用。

Server:apache tomcat                 ---表示服務器的類型

Content-Encoding: gzip                 -- 表示服務器發(fā)送給瀏覽器的數(shù)據(jù)壓縮類型

Content-Length: 80                    --表示服務器發(fā)送給瀏覽器的數(shù)據(jù)長度

Content-Language: zh-cn               --表示服務器支持的語言

Content-Type: text/html; charset=GB2312   --表示服務器發(fā)送給瀏覽器的數(shù)據(jù)類型及內(nèi)容編碼

Last-Modified: Tue, 11 Jul 2000 18:23:51 GMT  --表示服務器資源的最后修改時間

Refresh: 1;url=http://www.it315.org     --表示定時刷新

Content-Disposition: attachment; filename=aaa.zip --表示告訴瀏覽器以下載方式打開資源(下載文件時用到)

Transfer-Encoding: chunked

Set-Cookie:SS=Q0=5Lb_nQ; path=/search   --表示服務器發(fā)送給瀏覽器的cookie信息(會話管理用到)

Expires: -1                           --表示通知瀏覽器不進行緩存

Cache-Control: no-cache

Pragma: no-cache

Connection: close/Keep-Alive           --表示服務器和瀏覽器的連接狀態(tài)。close:關(guān)閉連接 keep-alive:保存連接

 

                     4.3 HttpServletResponse對象

                            HttpServletResponse對象修改響應信息:

 

                                               響應行:

                                                                 response.setStatus()  設置狀態(tài)碼

                                               響應頭:

                                                                 response.setHeader("name","value")  設置響應頭

                                               實體內(nèi)容:

                                                                 response.getWriter().writer();   發(fā)送字符實體內(nèi)容

                                                                 response.getOutputStream().writer()  發(fā)送字節(jié)實體內(nèi)容

 

                     4.4 案例- 請求重定向(Location)

                     4.5 案例- 定時刷新(refresh)

                     4.6 案例-content-Type作用

 

                   總結(jié):

                                     http協(xié)議: 瀏覽器和服務器之間數(shù)據(jù)傳輸?shù)母袷揭?guī)范

 

                                     1)http請求:

                                                        格式:

                                                                           請求行

                                                                           請求頭

                                                                           空行

                                                                           實體內(nèi)容(POST提交的數(shù)據(jù)在實體內(nèi)容中)

                                                        重點:

                                                                 使用HttpServletRequest對象: 獲取請求數(shù)據(jù)

 

                            2)http響應;

                                               格式:

                                                                 響應行

                                                                 響應頭

                                                                 空行

                                                                 實體內(nèi)容(瀏覽器看到的內(nèi)容)

                                               重點:

                           &nb

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/1944.html

相關(guān)文章

  • 微信小程序入門

    摘要:微信小程序框架結(jié)構(gòu)目前了解到的信息里發(fā)現(xiàn)微信小程序框架的結(jié)構(gòu)和特點跟之前用的很像,但是如何做到與后端服務器通信,如何建立數(shù)據(jù)庫并與數(shù)據(jù)庫通信還是需要新的探索。微信小程序網(wǎng)絡通信相關(guān)接口發(fā)起的是請求。 微信小程序框架結(jié)構(gòu):showImg(https://segmentfault.com/img/bVKi86?w=1430&h=942); 目前了解到的信息里發(fā)現(xiàn)微信小程序框架的結(jié)構(gòu)和特點跟...

    YacaToy 評論0 收藏0
  • 爬蟲入門到精通-HTTP協(xié)議的講解

    摘要:協(xié)議的講解本文章屬于爬蟲入門到精通系統(tǒng)教程第三講什么是協(xié)議引用自維基百科超文本傳輸協(xié)議英文,縮寫是互聯(lián)網(wǎng)上應用最為廣泛的一種網(wǎng)絡協(xié)議。通過或者協(xié)議請求的資源由統(tǒng)一資源標識符,來標識。假定其下層協(xié)議提供可靠的傳輸。 HTTP協(xié)議的講解 本文章屬于爬蟲入門到精通系統(tǒng)教程第三講 什么是HTTP協(xié)議? 引用自維基百科 超文本傳輸協(xié)議(英文:HyperText Transfer Protoco...

    Towers 評論0 收藏0
  • WebSocket系列之基礎知識入門

    摘要:概述本文是系列的第一篇,主要介紹相關(guān)的基礎協(xié)議知識和。客戶端收到響應后,立即發(fā)起下一次的請求。收到消息通過事件來接收消息。類型則需要傳遞一個對象作為參數(shù),相關(guān)的內(nèi)容也將在本系列第二篇中進行介紹。 概述 本文是WebSocket系列的第一篇,主要介紹WebSocket相關(guān)的基礎協(xié)議知識和API。由于WebSocket的相關(guān)介紹在MDN中分布較亂,初學者不太容易入門,因此通過本文將相關(guān)基礎...

    Yuqi 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<