Mobile app version of vmapp.org
Login or Join
Sue5673885

: Difference between the Accept and Content-Type HTTP headers So the Accept header tells the server the MIME-type of the resource the browser is looking for. For example, the server can send plain

@Sue5673885

Posted in: #ContentType #HttpHeaders

So the Accept header tells the server the MIME-type of the resource the browser is looking for. For example, the server can send plain text, HTML, JSON, etc.

OK, that makes sense, but when I look at the Content-Type header and it seems to be doing the same thing. For example, it tells the server that it wants text or JSON.

So what is the difference between Accept and Content-Type HTTP headers?

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Sue5673885

4 Comments

Sorted by latest first Latest Oldest Best

 

@Goswami781

It is a request-response conversation, so the client


sends a request of "Content-Type" and
expects to receive the response of "Accept" media type.

10% popularity Vote Up Vote Down


 

@Barnes591

Accept is like


Here is my request and I would like (to Accept) this response format


Content-Type is like


Here is my request (or response) and this (Content-Type) is the format of the content I am sending in my request (or response)

10% popularity Vote Up Vote Down


 

@Pierce454

As you correctly note, the Accept header is used by HTTP clients to tell the server what content types they'll accept. The server will then send back a response, which will include a Content-Type header telling the client what the content type of the returned content actually is.

However, as you may have noticed, HTTP requests can also contain Content-Type headers. Why? Well, think about POST or PUT requests. With those request types, the client is actually sending a bunch of data to the server as part of the request, and the Content-Type header tells the server what the data actually is (and thus determines how the server will parse it).

In particular, for a POST request resulting from an HTML form submission, the Content-Type of the request will (normally) be one of the standard form content types below, as specified by the enctype attribute on the <form> tag:


application/x-www-form-urlencoded (default, older, simpler, slightly less overhead for small amounts of simple ASCII text, no file upload support)
multipart/form-data (newer, adds support for file uploads, more efficient for large amounts of binary data or non-ASCII text)

10% popularity Vote Up Vote Down


 

@Carla537

Accept: is what the browser is able to digest, for example, all the languages someone can understand.
Content-Type: is what format the actual data is in, for example what language someone is speaking. Since computers can't (well, now they can) recognize other types like people can say "oh, he's German!" or "she's speaking Chinese!"

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme