What status code should I return if one of these pages was called without required parameters? (and therefore can't return any content).
usted podría escoger 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.
(resaltado por mí)
404 Not Found
es un subconjunto de 400 Bad Request
que podría tomarse así porque es muy claro acerca de lo que es esto:
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
No puedo sugerir que lo que hace ka Código de respuesta WEBDAV que no existe para los clientes HTTP que usan hipertexto, pero podría, es totalmente válido, usted es el codificador del servidor, puede tomar cualquier código de estado de resonse HTTP que considere adecuado para su cliente HTTP del cual usted es el diseñador también:
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.
entidad de solicitud de IIRC es el cuerpo de la solicitud. Entonces, si estás operando con cuerpos de solicitud, podría ser apropiado como escribió Julian.
Ha comentado:
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.
Eso podría ser, pero puede ser cualquier cosa expresada sintácticamente, toda la solicitud, sólo algunas cabeceras de petición, o una cabecera de la solicitud específica, la petición URI etc .. 400 no está específicamente sobre "sintaxis de cadena HTTP", es de hecho la respuesta general a un error del cliente:
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.
la parte importante es ahí donde se debe decirle al cliente lo que salió mal. El código de estado solo indica que algo salió mal (en la clase 4xx), pero HTTP no se ha diseñado específicamente para hacer que un parámetro de parte consulta-información faltable como una condición de error.De hecho, URI solo sabe que hay una parte consulta-info y no lo que significa.
Si crees que 400 es demasiado amplio, te sugiero que elijas 404 si el problema está relacionado con el URI, p. $_GET
variables.
Ver también (si eso no es un duplicado par): [código de estado HTTP para los malos datos] (http://stackoverflow.com/questions/1364527/http-status-code-for- datos incorrectos) – hakre
422 es totalmente apropiado. –
@JulianReschke Creo que 4918 podría hacer con algunas erratas, primero para especificar que actualiza 2616, y en segundo lugar para aclarar que los nuevos códigos de estado HTTP no son todos específicos de WebDAV. – Alnitak