415 Unsupported Media Type

We'd love to hear more about your role and the company you work for
Please help us by answering a few questions.

HTTP 415 Unsupported Media Type 用戶端錯誤回應狀態碼表示伺服器拒絕接受請求,因為訊息的內容格式是不受支援的。

格式問題可能是由於請求中指定的 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 標頭中指明該請求所需的內容類型:

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

規範

Specification
HTTP Semantics
# status.415

參見