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);
		Enumeration<String> headers=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("<h1>"+header_name+":"+header_value+"h1");
		}
		out.println("<h1>"+request.getRemoteAddr()+"<h1>");
	}

	/**
	 * @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、响应体:最后一部分(存放相应数据)

响应状态码:

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小郭同学忒骚了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值