415 Unsupported Media Type
HTTP **415 Unsupported Media Type** 客戶端錯誤響應 狀態碼錶示伺服器拒絕接受請求,因為訊息內容格式不受支援。
格式問題可能是由於請求指示的Content-Type或Content-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!"
}
如果伺服器實現至少期望Content-Type: application/json;作為該端點請求的MIME型別,則它可能會發送以下響應
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
規範
| 規範 |
|---|
| HTTP語義 # status.415 |