What status code should I return if one of these pages was called without required parameters? (and therefore can't return any content).
Вы можете выбрать 404 Not Found
:
The server has not found anything matching the Request-URI [assuming your required parameters are part of the URI, i.e. $_GET
]. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
(изюминка мной)
404 Not Found
является подмножеством 400 Bad Request
, которые могут быть приняты, а потому, что это очень ясно, о том, что это:
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
Я не могу на самом деле предположить, что вы рискуете ka WEBDAV, который не существует для HTTP-клиентов, использующих гипертекст, но вы можете, это абсолютно верно, что вы - серверный кодер, вы можете фактически принять любой код статуса ответа HTTP, который, по вашему мнению, подходит для вашего HTTP-клиента, которым вы являетесь дизайнер:
11.2. 422 Unprocessable Entity
The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions. For example, this error condition may occur if an XML request body contains well-formed (i.e., syntactically correct), but semantically erroneous, XML instructions.
Объект запроса IIRC является органом запроса. Поэтому, если вы работаете с органами запроса, это может быть уместно, как писал Джулиан.
Вы прокомментировали:
IMHO, the text for 400 speaks of malformed syntax. I would assume the syntax here relates to the syntax of HTTP string that the client sends across to the server.
Это может быть, но это может быть что угодно, синтаксически выражаются, весь запрос, только некоторые заголовки запроса, или конкретный заголовок запроса, запрос URI и т.д .. 400 не конкретно о «HTTP строки синтаксиса», это Infact общий ответ на ошибку клиента:
The 4xx class of status code is intended for cases in which the client seems to have erred. Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. These status codes are applicable to any request method. User agents SHOULD display any included entity to the user.
важной частью здесь, что вы должны сообщить клиенту, что пошло не так. Код состояния просто говорит, что что-то пошло не так (в классе 4xx), но HTTP не был специально разработан для того, чтобы исключить отсутствующий параметр детали запроса и информации как условие ошибки.По сути, URI знает только, что есть часть запроса-информации, а не то, что она означает.
Если вы считаете, что 400 слишком широк, я предлагаю вам выбрать 404, если проблема связана с URI. $_GET
переменные.
См также (если это не является дубликатом даже): [HTTP код состояния для плохих данных] (http://stackoverflow.com/questions/1364527/http-status-code-for- bad-data) – hakre
422 вполне уместно. –
@JulianReschke Я думаю, что 4918 мог бы сделать с некоторыми ошибками, во-первых, чтобы указать, что он обновляет 2616, а во-вторых, чтобы уточнить, что новые коды статуса HTTP не все специфичны для WebDAV. – Alnitak