首页
关于
Search
1
sql的注入原因和解决办法
145 阅读
2
SpringBoot整合腾讯云存储COS及基本使用,增删改查......
129 阅读
3
深究contains方法
100 阅读
4
多线程概述
74 阅读
5
学习的第一个注解@WebServlet - JavaWeb
73 阅读
默认分类
Java
C/C++
Mysql
JavaWeb
SpringBoot
算法
前端
Linux
Search
标签搜索
Spring
HTTP
Java
JavaWeb
IOC
mybatis
腾讯云
COS
云存储
CDN
redis
分布式
id
全局唯一id
Typecho
累计撰写
26
篇文章
累计收到
3
条评论
首页
栏目
默认分类
Java
C/C++
Mysql
JavaWeb
SpringBoot
算法
前端
Linux
页面
关于
搜索到
1
篇与
HTTP
的结果
2022-03-17
HTTP请求和响应的分析
get and post准备:index.html, GetHttp.java,PostHttp.javaindex.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/1.1)第二部分:状态码(HTTP协议中规定的响应状态号。不i痛的响应结果对应不同的号码)200表示响应成功。404表示资源不存在。要么是没有该资源,要么是路径写错了。405表示前端发生的请求方式和后端的处理方式不一致时发生。比如前段是发送post请求,后端是get方式处理。比如前端是发生post请求,后端是get方式处理。500表示服务器端的程序出现了异常,一般是服务器端导致的错误。小总结:以4开头,一般是浏览器端的错误导致的。以5开头,一般是服务器端的错误导致的。第三部分:状态的描述ok表示正常成功结束not found表示资源找不到响应头:响应的内容类型响应的内容长度响应时间......空白行:用来分隔”响应头“和“响应体”的。响应体:就是响应的正文,响应的正文被浏览器渲染,解释并执行,最终展现出的效果。分析:请求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分析请求行包括三部分第一部分:请求方式,常用的有两个getpost第二部分:URI什么是URI?统一资源标识符。代表网络中某个资源的名字。但是无法通过URI定位资源什么是URL?统一资源定位符。代表网络中某个资源。可以通过URL定位该资源。URI和URL的关系,区别URL包含URI。http://localhost:8080/test01/pages/http/http.html是URL/test01/pages/http/http.html是URI第三部分:HTTP协议版本号。请求体请求的主机主机的端口浏览器信息平台信息Cookie等等空白行分隔”请求体“和”请求体“。请求体向服务器发送的具体数据。get和post的区别怎么向服务器发送GET请求,怎么向服务器发送POST请求?到目前为止,只有一种情况可以发送POST请求:使用form表单,且form标签中的method属性值为“post”。其他情况一律是GET请求。在浏览器上直接输入URL回车,属于get请求。在浏览器直接点击超链接,属于get请求。使用form时,from标签中的method值为get。......GET请求和POST请求的区别get请求发送数据时,数据会挂在URL后面,以” ?“隔开,” ?“后面是数据。这样会导致数据显示在浏览器地址栏上。post请求发送数据的时候,在请求体中发送,不会显示在浏览器地址栏。get请求只能发送普通字符,并且字符串的长度有限制,不同浏览器现在不同,没有明确规范。get无法发送大量数据。post请求可以发送任何类型的数据,包括普通字符,流媒体信息,图片...post可以发送大量数据,理论上没有上限。get请求在W3C中是这样说的,get请求比较适合从服务器段获取数据。post请求在W3C中时这样说的:post请求比较适合向服务器端传送数据。get和post的安全性。get请求是安全的。为什么?从应用场景来说,get请求只是为了从服务器获取数据。不会对服务器造成威胁。post请求时危险的。为什么?因为post时向服务器提交数据,如果这些数据通过后门的方式进入到服务器当中,服务器是很危险的。一般情况下。拦截/监听的请求,大部分是post有些情况,比如get请求会使信息暴露在浏览器地址栏,这是因为使用了错误的请求方式造成的。使用规范请回看上面的7、8。get请求支持缓存。任何一个get请求都会被浏览器缓存起来。https://n.sinaimg.cn/default/590/w240h350/20220316/3a70-d24bfc7f073a3b02bbb1fef5aa17ccd4.jpg在浏览器缓存中,一个资源对应一个路径实际上,在发送get请求的时候,浏览器第一时间是在本地查找资源,找不到了才会去服务器获取。如何不让get走缓存?http:abc.com/img/1.jpg?t=1231234http:abc.com/img/1.jpg?t=1231234http:abc.com/img/1.jpg?t=系统毫秒数只要每次请求的路径不同即可,可以在文件末尾加上时间戳。post请求不支持缓存。因为post请求的一般是动态数据。get和post如何选择?看使用场景。如果想向服务器发送数据,建议get。如果想获取服务器上的资源,建议post。大部分表单提交都是post,因为form表单中需要填写大量数据,一般是要传给服务器来保存或修改的。表单中有敏感数据,建议使用post,因为get会回显数据在浏览器地址栏。做文件上传,一定是要post请求。get和post发送的数据格式时完全相同的,只不过时位置不一样。userName=lisi&passWord=123name是什么?以form表单为例:from表单中的input标签的name。value是什么?以form表单为例:from表单中的input标签的value。
2022年03月17日
35 阅读
0 评论
0 点赞