Sunday, August 5, 2012

Accept header vs Content-Type Header

I occasionally get confused between the Accept and the Content-Type Headers and this post is a way of clarifying the difference for myself. Let me summarize the difference to start with and then go onto a little bit of detail -
Accept and Content-type are both headers sent from a client(browser say) to a service.
Accept header is a way for a client to specify the media type of the response content it is expecting and Content-type is a way to specify the media type of request being sent from the client to the server.

To expand on this:

Accept header to quote the HTTP/1.1 RFC:

The Accept request-header field can be used to specify certain media types which are acceptable for the response. 
An example of an Accept header for a json request to a REST based service will be the following:
Accept: application/json

This is saying the response expected is a json content.

Content-Type to quote from the HTTP/1.1 RFC:

The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.
As a sample if a json is being sent from a browser to a server, then the content type header would look like this:
Content-Type: application/json


  1. Subtle but useful. Also note that there is a "Content-Type" in response headers as well. Not to be confused with the content type explained in the above article.

  2. nice and precise


  4. Thank you. Clear explanation.

  5. Can "Accept" header be a part of http response ?
    Can "Content-Type" header be present in http request?