当前位置:网站首页>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 不可以
边栏推荐
- Security level
- [understanding of opportunity -38]: Guiguzi - Chapter 5 flying clamp - warning one: there is a kind of killing called "killing"
- Can you really learn 3DMAX modeling by self-study?
- Zabbix
- Medusa installation and simple use
- 【LeetCode】501. Mode in binary search tree (2 wrong questions)
- February database ranking: how long can Oracle remain the first?
- [daily problem insight] Li Kou - the 280th weekly match (I really didn't know it could be so simple to solve other people's problems)
- Traditional chips and AI chips
- Missile interception -- UPC winter vacation training match
猜你喜欢

Variables in postman

Asp+access campus network goods trading platform

LeetCode 314. Binary tree vertical order traversal - Binary Tree Series Question 6

Traditional chips and AI chips

2021 Li Hongyi machine learning (1): basic concepts

Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘

Avoid material "minefields"! Play with super high conversion rate

Naacl 2021 | contrastive learning sweeping text clustering task

Design and implementation of community hospital information system

Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
随机推荐
Exploration of short text analysis in the field of medical and health (II)
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Zabbix
Limited query of common SQL operations
When the low alcohol race track enters the reshuffle period, how can the new brand break the three major problems?
A label making navigation bar
Collection of gmat750 wrong questions
ELFK部署
[uc/os-iii] chapter 1.2.3.4 understanding RTOS
spoon插入更新oracle数据库,插了一部分提示报错Assertion botch: negative time
Traditional chips and AI chips
Single line function*
Design and implementation of community hospital information system
Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
Which common ports should the server open
Hmi-31- [motion mode] solve the problem of picture display of music module
[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
Application and Optimization Practice of redis in vivo push platform
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
Action News