天天看點

Request擷取請求資料執行個體

Table of Contents

原理

繼承體系

資料格式

擷取請求資料

擷取請求行資料

擷取請求頭資料

Post方式擷取請求體

Request是tomcat建立的對象,請求過來的時候,tomcat建立Request封裝請求,實際上是RequestFacade
HttpServletRequest接口繼承ServletRequest接口,
Request擷取請求資料執行個體
 RequestFacade實作了HttpServletRequest
Request擷取請求資料執行個體
請求行 請求頭 請求空行 請求體
擷取請求方式:String getMethod() 擷取虛拟目錄:String getContextPath() 擷取Servlet路徑:String getServletPath() 擷取get方式請求參數:String getQueryString() 擷取請求URI:String getRequestURI() 擷取請求URL:StringBuffer getRequestURL() 擷取協定版本:String getProtocol() 擷取客戶機的IP位址:String getRemoteAddr()
Postman請求通路
Request擷取請求資料執行個體
背景輸出 請求方式: GET 虛拟目錄: /myRequest Servlet路徑: /requestDemo1 get方式請求參數: name=lin&age=23 請求URI: /myRequest/requestDemo1 請求URL: http://localhost:8080/myRequest/requestDemo1 協定及版本:HTTP/1.1 客戶機的IP位址: 0:0:0:0:0:0:0:1
Enumeration<String> getHeaderNames():擷取所有的請求頭名稱 String getHeader(String var1):通過請求頭的名稱擷取請求頭的值
通過Postman請求
Request擷取請求資料執行個體
cache-control :no-cache postman-token :95bc6857-e84c-4073-86bb-9a8e5dedd6a2 user-agent :PostmanRuntime/7.6.0 accept :*/* host :localhost:8080 accept-encoding :gzip, deflate connection :keep-aliv
BufferedReader getReader():擷取字元輸入流,隻能操作字元資料 ServletInputStream getInputStream():擷取位元組輸入流,可以操作所有類型選資料
用Postman請求
Request擷取請求資料執行個體
背景輸出: name=lin&age=27
可見,get請求和post請求,擷取請求參數的方式不一樣,下面就介紹一種異樣的方式

繼續閱讀