Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http中post和put的区别 #10

Open
huangchucai opened this issue Apr 13, 2019 · 0 comments
Open

Http中post和put的区别 #10

huangchucai opened this issue Apr 13, 2019 · 0 comments

Comments

@huangchucai
Copy link
Owner

Http中post和put的区别

在传输功能上,二者并没有多大的区别,起初就没有put方法。从本质上看,我们要理清这二者的区别,必须要明白一个概念

幂等

首先解释幂等,幂等是数学的一个用语,对于单个输入或者无输入的运算方法,如果每次都是同样的结果,则称其是幂等的

对于两个参数,如果传入值相等,结果也等于每个传入值,则称其为幂等的,如min(a,b)

Post请求

用于提交请求,可以更新和创建数据,是非幂等的

举个栗子: 当我们创建新用户的时候,每次都是传递账户名和密码,但是每次都生成一个新的账号,并不是同一个账号,这个时候就应该用post

Put请求

用于向指定的URL更新数据,是幂等的

举个栗子:同样是用户模块,当我们修改账号和密码的时候,还是和原来的那个账户是一样的,只是更新了值

总结

很简单,如果该更新对应的URI多次调用的结果一致,则PUT。如果每次提交相同的内容,最终结果不一致的时候,用POST。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant