Difference between put and post usage in HTTP protocol

Source: Internet
Author: User

http://blog.csdn.net/mad1989/article/details/7918267

There is a point of view that you should use post to create a resource, to update a resource with put, and that you should use put to create a resource, post to update a resource, and the idea that you can create or update a resource with any of the put and post. These views only see the style, the debate is just arguing about which style is better, in fact, put or post, not to see whether this is to create or update the resources of the action, this is not a question of style, but a semantic problem.



in HTTP, put is defined as a idempotent method, post is not, this is a very important difference.



    "Methods can also have" "Idempotence" in ", aside from error or expiration issues) The side-effects of N > 0 Identical requests is the same as in a single request.



above is to say that if a method repeats repeatedly, the effect is the same, that is idempotent.



      to give a simple example, if there is a blog system that provides a web API, the pattern is this http://superblogging/blogs/post/{blog-name Simply, replace {blog-name} with our blog name, send an HTTP put or POST request to this URI, and the body of HTTP is Bowen, a simple REST API example. Should we use the Put method or Post method? Depending on whether the behavior of the rest service is idempotent, if we send two http://superblogging/blogs/post/Sample requests, what is the behavior of the server side? If two blog posts are generated, it means that the service is not idempotent, because the side effects of multiple use have been, if the latter request to cover the first request, the service is idempotent. In the former case, you should use the Post method, and in the latter case you should use the Put method.



You may think that the difference between the two methods is not a big deal, with the wrong will not have any problems, but your service on the Internet, if you do not comply with the specifications of the HTTP protocol, you can cause trouble to themselves. For example, Google Crawler will also visit your service, if you let a service that is not indempotent can be accessed using Indempotent method, then your server status may be crawler modified, this should not happen.

Foreign article extracts, specifically forget the name of the author and URL ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.