根据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/