11

What are the differences and advantages of using one over the other:

Accept: application/json;charset=utf-8

versus:

Accept: application/json
Accept-Charset: utf-8

Is the first form compliant to rfc 2616?

Note: could be json or xml, etc.

Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
  • 1
    Not a definite answer, but check [this related question](http://stackoverflow.com/questions/7055849/accept-and-accept-charset-which-is-superior) for some comments – Martin Nov 03 '11 at 15:29
  • It is for "Server" to consider charset in Accept or not. But all the agents do work on Accept-charset https://developer.mozilla.org/en-US/docs/HTTP/Content_negotiation – Optional Sep 26 '13 at 09:50

1 Answers1

3

Both of them are compliant. But I prefer second one.

"charset" parameter is for media type and media types are defined by IANA, not by RFC 2616.

  • Even if the server understands RFC 2616, you cannot be sure it understands "charset" parameter.
  • Some media types may not have "charset" parameter.
npcode
  • 1,370
  • 1
  • 14
  • 29
  • 1
    If a media type doesn't have a charset parameter then *both* forms are meaningless. – Julian Reschke Oct 27 '13 at 20:58
  • @JulianReschke Why an Accept-Charset form is also meaningless if a media type doesn't have a "charset" parameter? RFC 2616 and draft-ietf-httpbis-p2-semantics-24 doesn't say that a charset in an Accept-Charset header is equivalent to a "charset" parameter for a media type. – npcode Oct 28 '13 at 12:09
  • do you have an example of a media type that supports different charsets but does not have a charset param? – Julian Reschke Oct 28 '13 at 20:12
  • @JulianReschke [application/ld+json](http://www.iana.org/assignments/media-types/application/ld+json) does not have a charset parameter and RFC 6839 says "Per [RFC4627], JSON is allowed to be represented using UTF-8, UTF-16, or UTF-32." – npcode Oct 29 '13 at 17:38