炯炯有神网

HTTP学习

HTTP学习

1、学习HTTP简介

概念:超文本传输协议,学习规定了浏览器和服务器之间数据传输规则

HTTP协议特点:

1、学习基于TCP协议:面向连接,学习安全

2、学习 基于请求—响应模型的学习:一次请求对应一次响应

3、HTTP协议是学习无状态的协议:对于实物处理没有记忆能力。每次请求响应都是学习独立的

      缺点:多次请求间不能共享数据

      优点:速度快

 2、HTTP—请求数据格式

package first;import java.io.IOException;import java.io.PrintWriter;import java.util.Enumeration;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.jasper.tagplugins.jstl.core.Out;/** * Servlet implementation class Servlet01 */@WebServlet("/Servlet01")public class Servlet01 extends HttpServlet { 	private static final long serialVersionUID = 1L;           /**     * @see HttpServlet#HttpServlet()     */    public Servlet01() {         super();        // TODO Auto-generated constructor stub    }	/**	 * @see HttpServlet#doGet(HttpServletRequest request,学习 HttpServletResponse response)	 */	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 		// TODO Auto-generated method stub		//response.getWriter().append("Served at: ").append(request.getContextPath());		String account=request.getParameter("account");		String psd=request.getParameter("psd");		PrintWriter out=response.getWriter();		out.println(account);		out.println(psd);		Enumerationheaders=request.getHeaderNames();		response.setContentType("text/html;charset=utf_8");		while(headers.hasMoreElements()) { 			String header_name=headers.nextElement();			String header_value=request.getHeader(header_name);			out.println("

"+header_name+":"+header_value+"h1"); } out.println("

"+request.getRemoteAddr()+"

"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); }}

host:localhost:8080h1

connection:keep-aliveh1

content-length:19h1

cache-control:max-age=0h1

sec-ch-ua:"Microsoft Edge";v="105", " Not;A Brand";v="99", "Chromium";v="105"h1

sec-ch-ua-mobile:?0h1

sec-ch-ua-platform:"Windows"h1

upgrade-insecure-requests:1h1

origin:http://localhost:8080h1

content-type:application/x-www-form-urlencodedh1

user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42h1

accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9h1

sec-fetch-site:same-originh1

sec-fetch-mode:navigateh1

sec-fetch-user:?1h1

sec-fetch-dest:documenth1

referer:http://localhost:8080/Chapter1/firstJSP.jsph1

accept-encoding:gzip, deflate, brh1

accept-language:zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6h1

cookie:JSESSIONID=AD727F0589AD364C4C9ED5FF777CC4DFh1

0:0:0:0:0:0:0:1

 

请求数据的3部分:

  1. 请求行:请求数据的第一行(get:请求方式,/表示请求资源路径,学习HTTP/1.1表示协议版本)
  2. 请求头:第二行开始(格式为key:value形式)

       3. 请求体:POST请求的学习最后一部分(存放请求参数)

 

 GET请求和POST请求的区别:

1、GET:请求参数在请求行中,学习没有请求体

      POST:请求在请求体

2、学习GET请求:参数大小有限制

3、学习HTTP—响应数据格式

1、学习响应行:响应数据的第一行(HTTP/1.1表示协议版本,200表示响应状态码,OK表示状态码描述) 

2、响应头:第二行开始,(格式为key:value)

3、响应体:最后一部分(存放相应数据)

响应状态码:

 

 

未经允许不得转载:炯炯有神网 » HTTP学习