版权属于:
Hello World
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
准备:index.html, GetHttp.java,PostHttp.java
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>GET请求</h1>
<form action="/test01/GetHttp" method="get">
userName<input type="text" name="userName"><br>
passWord <input type="password" name="passWord"><br>
<input type="submit" value="login">
</form>
<br><br>
<h1>post请求</h1>
<form action="/test01/PostHttp" method="post">
userName <input type="text" name="userName"><br>
passWord <input type="password" name="passWord"><br>
<input type="submit" value="login">
</form>
</body>
</html>
GetHttp
@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<!doctype html>");
out.print("<html>");
out.print(" <head>");
out.print(" <title>Form Get Servlet</title>");
out.print(" </head>");
out.print(" <body>");
out.print(" <h1>");
out.print(" from get servlet");
out.print(" </h1>");
out.print(" </body>");
out.print("</html>");
}
PostHttp
@Override
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<!doctype html>");
out.print("<html>");
out.print(" <head>");
out.print(" <title>Form Get Servlet</title>");
out.print(" </head>");
out.print(" <body>");
out.print(" <h1>");
out.print(" from get servlet");
out.print(" </h1>");
out.print(" </body>");
out.print("</html>");
}
HTTP具体报文
HTTP/1.1 200 ok //状态行
Content-Type: text/html;charset=ISO-8859-1 //响应头
Content-Length: 166
Date: Thu, 17 Mar 2022 04:22:32 GMT
Keep-Alive: timeout=20
Connection: keep-alive
//空白行
<!doctype html> //响应体
<html>
<head>
<title>Form Get Servlet</title>
</head>
<body>
<h1>
from get servlet
</h1>
</body>
</html
状态行
三部分组成
第二部分:状态码(HTTP协议中规定的响应状态号。不i痛的响应结果对应不同的号码)
405表示前端发生的请求方式和后端的处理方式不一致时发生。
小总结:
第三部分:状态的描述
响应头:
空白行:
响应体:
get请求内容
Request URL: http://localhost:8080/test01/GetHttp?userName=lisi&passWord=123 //请求行
Request Method: GET //请求头
Status Code: 200
Remote Address: [::1]:8080
Referrer Policy: strict-origin-when-cross-origin
HTTP/1.1 200
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 188
Date: Thu, 17 Mar 2022 04:44:40 GMT
Keep-Alive: timeout=20
Connection: keep-alive
GET /test01/GetHttp?userName=lisi&passWord=123 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"
sec-ch-ua-mobile: ?1
sec-ch-ua-platform: "Android"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Mobile Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: http://localhost:8080/test01/pages/http/http.html
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: Idea-4bb2b176=f38436c5-5137-4805-8d0a-75f83df8839d
//空白行
//请求体
post请求内容
POST /test01/PostHttp HTTP/1.1 //请求行
Host: localhost:8080 //请求头
Connection: keep-alive
Content-Length: 28
Cache-Control: max-age=0
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"
sec-ch-ua-mobile: ?1
sec-ch-ua-platform: "Android"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Mobile Safari/537.36
Origin: http://localhost:8080
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: http://localhost:8080/test01/pages/http/http.html
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7
Cookie: Idea-4bb2b176=f38436c5-5137-4805-8d0a-75f83df8839d
//空白行
userName: achong //请求体
passWord: 123
分析
请求行
包括三部分
第一部分:请求方式,常用的有两个
第二部分:URI
URI和URL的关系,区别
请求体
空白行
请求体
get和post的区别
怎么向服务器发送GET请求,怎么向服务器发送POST请求?
其他情况一律是GET请求。
GET请求和POST请求的区别
get和post的安全性。
get请求是安全的。为什么?
post请求时危险的。为什么?
get请求支持缓存。
任何一个get请求都会被浏览器缓存起来。
如何不让get走缓存?
get和post如何选择?
看使用场景。
get和post发送的数据格式时完全相同的,只不过时位置不一样。
name是什么?
value是什么?
评论 (0)