http - 如何解释 HTTP Accept header ?

标签 http rest

根据HTTP1.1 spec , 以下内容的 Accept header

Accept: text/plain; q=0.5, text/html, text/x-dvi; q=0.8, text/x-c

被解释为

text/html and text/x-c are the preferred media types, but if they do not 
exist, then send the text/x-dvi entity, and if that does not exist, send 
the text/plain entity

让我们将标题更改为:

Accept: text/html, text/x-c

如果这两个都不被接受,返回什么?例如假设我只支持 application/json

最佳答案

也许你应该用 406 Not Acceptable 来回应。这就是我阅读 this 的方式.

或者 415 不支持的媒体类型

我会选择 406,因为在那种情况下,根据规范,响应应该包括备选方案列表。尽管我不清楚该列表应该是什么样子。

关于http - 如何解释 HTTP Accept header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/776212/

相关文章:

Go 中的 HTTP header 名称

http - Golang 从内存中提供静态文件

spring - 仅在第一次调用时调查 HTTP 406 错误代码

ios - 从 Swift 函数中的异步调用返回数据

java - HttpResponseProxy HTTP/1.0 401 未经授权

WordPress wp-admin 重定向到 https

php - 表单后操作 : not seeing query parameters in $_POST

node.js - 如何在loopback中制定API限速策略

java - 通过 rest-engine 启动时从 Camunda 进程返回数据

C:通过HTTP请求上传文件到Google Drive的错误408响应