JavaWeb:浏览器post和get请求

HTTP是超文本协议的缩写,是学习javaweb的基石

HTTP有2个版本,1.0和1.1,目前1.0不用了,因为他只能请求服务器一个资源,但是1.1可以请求多个

浏览器是request请求,服务器是response回应

http请求?
客户端连接服务器后,向服务器请求某个web资源
称之为客户端向服务端发送了一个http请求

以下都是浏览器对服务器的requests

运行<html>
<head>
<meta name="content-type" content="text/html"; charset="UTF-8">
</head>
<body>
<form action="#" method="post">
name:<input type="text" name="name"><br>
age:<input type="text" name="age"><br>
<input type="submit" value="submit">
</form>
</head>
</html>

然后浏览器F12---network---文件名---requests header----view parsed
什么也不输
//请求方式,请求资源名称 HTTP版本
GET /web/1.html HTTP/1.1  
//消息头以下
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: JSESSIONID=3ED0B5A98AA2590DB0B296C9D4206940
If-None-Match: W/"278-1567959082562"
If-Modified-Since: Sun, 08 Sep 2019 16:11:22 GMT

//以下是post
//post是你输入数据后,重复上述步骤
POST /web/1.html HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 18
Cache-Control: max-age=0
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost:8080/web/1.html
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: JSESSIONID=3ED0B5A98AA2590DB0B296C9D4206940

你输入admin,123,就构成请求体
http请求包括请求行,请求头,请求体
请求行就是第一行,请求头就是Headers,请求体就是你写的,在header的form Data
请求方法还有很多,比如OPTIONS

如果我们把html代码改为
<html>
<head>
<meta name="content-type" content="text/html"; charset="UTF-8">
</head>
<body>
<form action="#" method="get">
name:<input type="text" name="name"><br>
age:<input type="text" name="age"><br>
<input type="submit" value="submit">
</form>
</head>
</html>
重复上述步骤
什么也不输
你会发现url变了
http://localhost:8080/web/1.html?name=&age=#

GET /web/1.html?name=&age= HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost:8080/web/1.html
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: JSESSIONID=3ED0B5A98AA2590DB0B296C9D4206940
If-None-Match: W/"277-1567959861395"
If-Modified-Since: Sun, 08 Sep 2019 16:24:21 GM

输了之后http://localhost:8080/web/1.html?name=admin&age=123#
GET /web/1.html?name=admin&age=123 HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost:8080/web/1.html?name=&age=
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: JSESSIONID=3ED0B5A98AA2590DB0B296C9D4206940
If-None-Match: W/"277-1567959861395"
If-Modified-Since: Sun, 08 Sep 2019 16:24:21 GM

总结:
GET:地址后以?的形式上交给服务器,多个数据之间用&分隔
POST:在请求体中

GET一般有长度大小限制
POST发送数据无限制
浏览器默认是GET

请求头:
1.Accept:浏览器通知服务器,浏览器可以接收的数据类型
2.Accept-charset:浏览器通知服务器,浏览器支持的字符集
3.Accept-Encoding:浏览器通知服务器,浏览器支持的压缩格式
4.Accept-Language:浏览器通知服务器,浏览器支持的语言环境
5.HOST:浏览器访问的主机名称
6.if-modified-since:浏览器询问服务器,浏览器本地是否修改过
7.Referer:浏览器通知服务器,浏览器当前页来自哪个页面
8.user-agent:浏览器通知服务器,浏览器端的基本信息
9.connection:浏览器保持服务器,是否保持连接
10.Date:浏览器通知服务器,浏览器当前时间

个人觉得post请求和get请求都是针对浏览器的,只是url有没有加参数
requests和response包括这两个

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值