415 Unsupported Media Type

HTTP 415 不支援的媒體型別 客戶端錯誤響應狀態碼錶示伺服器拒絕接受請求,因為訊息內容格式不受支援。

格式問題可能源於請求中指示的Content-TypeContent-Encoding,或者是在處理請求訊息內容時發生的。某些伺服器可能對請求的預期Content-Type有嚴格要求。例如,傳送UTF8而不是UTF-8來指定UTF-8字元集可能導致伺服器認為媒體型別無效。

狀態

http
415 Unsupported Media Type

示例

缺少內容型別

在以下示例中,Content-Type頭完全缺失。

http
POST /comments HTTP/1.1
Host: example.com
Content-Length: 23

{
  "user": "belgin",
  "comment": "LGTM!"
}

如果伺服器實現在該端點的請求中期望至少有一個 MIME 型別Content-Type: application/json;,它可能會發送以下響應:

http
HTTP/1.1 415 Unsupported Media Type
Date: Fri, 28 Jun 2024 12:00:00 GMT
Server: Apache/2.4.41 (Ubuntu)
Accept-Post: application/json; charset=UTF-8
Content-Length: 0

無效內容型別

在以下示例中,當內容位於請求正文中時,Content-Type頭被錯誤地設定為 URL 編碼的表單資料。

http
POST /comments HTTP/1.1
Host: example.com
Content-Length: 23
Content-Type: application/x-www-form-urlencoded

{
  "user": "belgin",
  "comment": "LGTM!"
}

在這種情況下,伺服器會響應 415 狀態碼,並在Accept-Post頭中指明請求所需的 Content-Type。

http
HTTP/1.1 415 Unsupported Media Type
Date: Fri, 28 Jun 2024 12:00:00 GMT
Server: Apache/2.4.41 (Ubuntu)
Accept-Post: application/json; charset=UTF-8
Content-Length: 0

規範

規範
HTTP 語義
# status.415

另見