意義
伺服器要求請求必須是條件式的(If-Match 等),以防止更新遺失。
常見原因
- 在強制樂觀鎖定的 API 上送出不含 If-Match 的 PUT 或 PATCH
解決方法
用戶端或訪客
先 GET 資源取得 ETag,更新時在 If-Match 中附上它。
網站或 API 的維護者
在本文中說明需要哪個標頭。
回應範例
HTTP/1.1
HTTP/1.1 428 Precondition Required
Date: Tue, 07 Oct 2025 09:30:00 GMT
Server: nginx
Content-Type: application/problem+json
{
"type": "about:blank",
"title": "Precondition Required",
"status": 428,
"detail": "Send If-Match with the ETag you last read."
} 規範
常見問題
› API 為什麼要求 If-Match?
為了防止兩個用戶端在不知情的情況下互相覆寫變更。
› 428 與 412 的差別?
428:沒有送出先決條件。412:有送出但不成立。