What status code should I return if one of these pages was called without required parameters? (and therefore can't return any content).
Bạn có thể chọn 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.
(điểm nhấn của tôi)
404 Not Found
là một tập hợp con của 400 Bad Request
có thể được thực hiện như là tốt vì nó rất rõ ràng về điều này là:
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
Tôi thực sự không thể đề xuất bạn chụp ảnh Mã phản hồi ka WEBDAV không tồn tại cho các máy khách HTTP sử dụng siêu văn bản, nhưng bạn có thể, nó hoàn toàn hợp lệ, bạn là người lập trình máy chủ, bạn có thể thực sự lấy bất kỳ mã trạng thái phản hồi HTTP nào mà bạn thấy phù hợp với ứng dụng khách HTTP của mình. nhà thiết kế:
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.
Thực thể yêu cầu IIRC là cơ quan yêu cầu. Vì vậy, nếu bạn đang hoạt động với các cơ quan yêu cầu, nó có thể thích hợp như Julian đã viết.
Bạn nhận xét:
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.
Đó có thể, nhưng nó có thể là bất cứ điều gì cú pháp đã bày tỏ, toàn bộ yêu cầu, chỉ có một số tiêu đề yêu cầu, hoặc một tiêu đề yêu cầu cụ thể, yêu cầu URI vv .. 400 không phải là đặc biệt về "chuỗi cú pháp HTTP", đó là infact câu trả lời chung một lỗi khách hàng:
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.
phần quan trọng là ở đây mà bạn phải nói với khách hàng những gì đã xảy ra. Mã trạng thái chỉ nói rằng đã xảy ra sự cố (trong lớp 4xx), nhưng HTTP chưa được thiết kế đặc biệt để làm cho tham số phần thông tin truy vấn bị thiếu đáng chú ý là điều kiện lỗi.Thực tế, URI chỉ biết rằng có một phần truy vấn-thông tin chứ không phải ý nghĩa của nó.
Nếu bạn cho rằng 400 quá rộng, tôi khuyên bạn nên chọn 404 nếu sự cố có liên quan đến URI, ví dụ: $_GET
biến.
Xem cũng (nếu đó không phải là một bản sao chẵn): [mã trạng thái HTTP cho dữ liệu xấu] (http://stackoverflow.com/questions/1364527/http-status-code-for- dữ liệu xấu) – hakre
422 hoàn toàn phù hợp. –
@JulianReschke Tôi nghĩ rằng 4918 có thể làm với một số errata, trước hết phải xác định rằng nó cập nhật 2616, và thứ hai để làm rõ rằng các mã trạng thái HTTP mới không phải là tất cả các WebDAV cụ thể. – Alnitak