当前位置:网站首页>2.常见的请求方法
2.常见的请求方法
2022-07-05 02:41:00 【_语墨】
请求方法是请求行中的第一个单词,它向服务器描述了客户端发出请求的动作类型。在 HTTP 协议中,不同的请求方法只是包含了不同的语义,但服务器和浏览器的一些约定俗成的行为造成了它们具体的区别
在实践中,客户端和服务器慢慢的形成了一个共识,约定俗成的规定了一些常见的请求方法:
- GET,表示向服务器获取资源。业务数据在请求行中,无须请求体
- POST,表示向服务器提交信息,通常用于产生新的数据,比如注册。业务数据在请求体中
- PUT,表示希望修改服务器的数据,通常用于修改。业务数据在请求体中
- DELETE,表示希望删除服务器的数据。业务数据在请求行中,无须请求体。
- OPTIONS,发生在跨域的预检请求中,表示客户端向服务器申请跨域提交
- TRACE,回显服务器收到的请求,主要用于测试和诊断
- CONNECT,用于建立连接管道,通常在代理场景中使用,网页中很少用到
GET和POST的区别
由于浏览器和服务器约定俗成的的规则,造成了GET和POST请求在web中的区别:
1.浏览器在发送GET请求时,不会附带请求体
2.GEt请求的传递信息量有限,适合传递少量数据;POST请求的传递信息量是没有限制的,适合传输大量数据。
3.GET请求只能传递ASCII数据,遇到非ASCII数据需要进行编码;POST请求没有限制。
4.大部分GET请求传递的数据都附带在path参数中,能够通过分享地址完整的重现页面,但同时也暴露了数据,若有敏感数据传递,不应该使用GET请求,至少不应该放到path中。
5.刷新页面时,若当前的页面是通过POST请求得到的,则浏览器会提示用户是否重新提交。若是GET请求得到的页面则没有提示。
6.GET请求的地址可以被保存为书签,POST不可以。
面试题
1.http 常见请求方法有哪些?
- GET,表示向服务器获取资源
- POST,表示向服务器提交信息,通常用于产生新的数据,比如注册
- PUT,表示希望修改服务器的数据,通常用于修改
- DELETE,表示希望删除服务器的数据
- OPTIONS,发生在跨域的预检请求中,表示客户端向服务器申请跨域提交
- TRACE,回显服务器收到的请求,主要用于测试和诊断
- CONNECT,用于建立连接管道,通常在代理场景中使用,网页中很少用到
2.GET 和 POST 的区别
从 http 协议的角度来说,GET 和 POST 它们都只是请求行中的第一个单词,除了语义不同,其实没有本质的区别。
之所以在实际开发中会产生各种区别,主要是因为浏览器的默认行为造成的。
受浏览器的影响,在实际开发中,GET 和 POST 有以下区别:
1.浏览器在发送 GET 请求时,不会附带请求体
2.GET 请求的传递信息量有限,适合传递少量数据;POST 请求的传递信息量是没有限制的,适合传输大量数据。
3.GET 请求只能传递 ASCII 数据,遇到非 ASCII 数据需要进行编码;POST 请求没有限制
4.大部分 GET 请求传递的数据都附带在 path 参数中,能够通过分享地址完整的重现页面,但同时也暴露了数据,若有敏感数据传递,不应该使用 GET 请求,至少不应该放到 path 中
5.刷新页面时,若当前的页面是通过 POST 请求得到的,则浏览器会提示用户是否重新提交。若是 GET 请求得到的页面则没有提示。
6.GET 请求的地址可以被保存为浏览器书签,POST 不可以
边栏推荐
- Action News
- Yolov5 model training and detection
- Zabbix
- Prometheus monitors the correct posture of redis cluster
- 返回二叉树中两个节点的最低公共祖先
- 2021 Li Hongyi machine learning (3): what if neural network training fails
- Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
- The phenomenology of crypto world: Pioneer entropy
- Why is this an undefined behavior- Why is this an undefined behavior?
- Last words record
猜你喜欢
Hmi-31- [motion mode] solve the problem of picture display of music module
2021 Li Hongyi machine learning (1): basic concepts
Traditional chips and AI chips
College Students' innovation project management system
Apache build web host
Naacl 2021 | contrastive learning sweeping text clustering task
How to make a cool ink screen electronic clock?
Introduce reflow & repaint, and how to optimize it?
【LeetCode】404. Sum of left leaves (2 brushes of wrong questions)
Visual studio 2019 set transparent background (fool teaching)
随机推荐
[200 opencv routines] 99 Modified alpha mean filter
2021 Li Hongyi machine learning (1): basic concepts
Unpool(nn.MaxUnpool2d)
Character painting, I use characters to draw a Bing Dwen Dwen
Leetcode takes out the least number of magic beans
Advanced learning of MySQL -- Application -- Introduction
Yolov5 model training and detection
The most powerful new household god card of Bank of communications. Apply to earn 2100 yuan. Hurry up if you haven't applied!
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
Security level
Hmi-31- [motion mode] solve the problem of picture display of music module
Practical case of SQL optimization: speed up your database
Medusa installation and simple use
Apache build web host
[technology development-26]: data security of new information and communication networks
Grub 2.12 will be released this year to continue to improve boot security
问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘
Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
Avoid material "minefields"! Play with super high conversion rate
【LeetCode】98. Verify the binary search tree (2 brushes of wrong questions)