: When to reply 400 Bad Request According to www.w3.org, a Web server should reply with status code 400 Bad Request if: "The request could not be understood by the server due to malformed
According to w3.org, a Web server should reply with status code 400 Bad Request if:
"The request could not be understood by the server due
to malformed syntax. The client SHOULD NOT repeat the
request without modifications"
Does that mean only request that violates some HTTP spec?
Or does it include a request that my particular Web app thinks is broken?
When would you reply 400?
For example, if my Web app expects a query string to always include a "function=..." parameter, would you reply code 400 Bad Request or 403 Forbidden? (403 means that "The server understood the request, but is refusing to fulfill it.")
More posts by @Speyer207
1 Comments
Sorted by latest first Latest Oldest Best
My interpretation of that header is that the HTTP specification was not followed properly and a required field is missing or bad data is provided. For example a header is missing or invalid characters are used in the request, etc.
Some malformed request exam-ple:
GET /images/logo.png HTTP/2 # there is no HTTP 2
POTT /images/logo.png HTTP/1.1 # POTT should be POST
Accept-Language en-US # Missing colon after header name
Your example seems like a legitimate usage of that HTTP response code. However, I suspect this would be better handled in your application. If that parameter is missing you can serve up a much prettier and more through error message. You can also have the page report back to you about the error so you can investigate it if necessary.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.