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

另见