Under what circumstances will an http request return 409

Source: Internet
Author: User
For example, after a non-advertisement chalk web site is used as an online question library website (each time you select the answer to a question, a request is sent to submit the question id and useranswer to the server, click the back button of the browser, and send the question id and useranswer request to obtain the form when the question is answered... for example, non-advertising
Chalk net, an online question library website
(Each time you select the answer to a question, a request is sent to submit the question id and useranswer to the server)
After submitting the exam, click the back button in the browser. when the question is answered, the request for question id and useranswer will receive the status code 409 conflict.
Obviously, this is a mechanism to prevent questions from being submitted.
How can this problem be achieved?
Allow http to automatically return 409

========================================
Please refer to the put submission method in Popular Science. If you have good article resources, please submit them ~ Thank you.

For post requests, I can see two different types of Data: Request Payload and Form Data in the http header information of chrome development tools.
I can't see put. Is it hidden in the uri address?

Reply content:

For example, non-advertising
Chalk net, an online question library website
(Each time you select the answer to a question, a request is sent to submit the question id and useranswer to the server)
After submitting the exam, click the back button in the browser. when the question is answered, the request for question id and useranswer will receive the status code 409 conflict.
Obviously, this is a mechanism to prevent questions from being submitted.
How can this problem be achieved?
Allow http to automatically return 409

========================================
Please refer to the put submission method in Popular Science. If you have good article resources, please submit them ~ Thank you.

For post requests, I can see two different types of Data: Request Payload and Form Data in the http header information of chrome development tools.
I can't see put. Is it hidden in the uri address?

409 Conflict

The request cannot be completed because of a conflict with the current status of the requested resource. This code can only be used in such cases:

The user is considered to be able to resolve the conflict and will resubmit a new request. The response should contain sufficient information for the user to find the source of the conflict.

A conflict usually occurs in the processing of PUT requests.

For example, in a version check environment, the version information contained in a PUT request to modify a specific resource conflicts with a previous (third-party) request, in this case, the server should return a 409 error, notifying the user that the request cannot be completed. In this case, the response entity may include a comparison between two conflicting versions, so that you can resubmit the new versions after merging.

Therefore, after you roll back, return409In my personal opinion, it should be used improperly. If 409 is used here, he should tell you that there is a conflict and how to modify it, however, I don't think there are any suggestions for the change, and I certainly haven't provided you with the modification method.

Next, let's talk about the implementation. First, we have to satisfy a state, that is, when XX happens, I will send 409:

phpif($someError) {  header("HTTP/1.0 409 Conflict", true);}}

The second parameter indicates whether to use the current replacement if the same type of header has been sent before. The default value istrueBut if you want them to coexist, usefalseYou can.

php
  

In HTTP, PUT is defined as the idempotent method, and POST is not. This is an important difference.

"Methods can also have the property of" idempotence "in that (aside from error or expiration issues) the side-effects of N> 0 identical requests is the same as for a single request."

In the above words, if a method is repeatedly executed multiple times, the results will be the same, that is, idempotent.

For example, a blog system provides a Web API in the http: // superblogging/blogs/post/{blog-name} mode, replace {blog-name} with our blog name and send an http put or POST request to this URI. The HTTP body is a blog, which is a simple example of rest api. Should we use the PUT method or the POST method? It depends on whether the behavior of this REST service is idempotent. If we send two http: // superblogging/blogs/post/Sample requests, what kind of behavior is the server side? If two blog posts are generated, it indicates that this service is not idempotent, because multiple use operations have a side effect. If the next request overwrites the first one, the service is idempotent. In the previous case, the POST method should be used. In the latter case, the PUT method should be used.

Maybe you will think that the difference between the two methods is no big deal, and there will be no problems if you use the wrong method, but if your service is put on the internet, if you do not follow the HTTP protocol specifications, it may cause troubles to you. For example, Google Crawler may also access your service. If a service that is not indempotent can be accessed using the indempotent method, the status of your server may be modified by the Crawler, this should not happen.
Excerpt from foreign articles. The author and url are missing ~

It cannot be automated. The application provides an interface for you to set http status codes and specific messages. Take php as an example:

header('HTTP/1.1 409 Conflict', true, 409);

You can also:int http_response_code ([ int $response_code ] )(Php> = 5.4 required)

If the question tag is PHP, use it to answer the question.

This is actually a semantic design, which is actually implemented through code. For example:

phpif($someThingWrong){    http_response_code(409);    exit();}

The above Code requires PHP ≥ 5.4.0, other versions please refer to: http://php.net/http_response_code#107261

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.