Accept header vs Content-Type Header
source link: http://www.java-allandsundry.com/2012/08/accept-header-vs-content-type-header.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Accept header vs Content-Type Header
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:An example of an Accept header for a json request to a REST based service will be the following:The Accept request-header field can be used to specify certain media types which are acceptable for the response.
Accept: application/json
This is saying the response expected is a json content.
Content-Type to quote from the HTTP/1.1 RFC:
As a sample if a json is being sent from a browser to a server, then the content type header would look like this: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.
Content-Type: application/json
8 comments:
- AnonymousMay 22, 2013 at 2:40 AM
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.
Reply - AnonymousNovember 27, 2015 at 4:17 AM
Can "Accept" header be a part of http response ?
Reply
or
Can "Content-Type" header be present in http request? Accept Request Header: If You Make Request To Server via HTTP, It Is Possible to specify which type of response you want by setting "Accept" request Header.
Reply
so, finally Accept Request Header used to get specific HTTP Response.
in Spring-rest: Accept Header ---- @ResponseBody( Uses Produces="MiMEType")
Content-Type Request Header: Which Tells to server which type of request coming from client.
in Spring-rest : Content-Type ----- @RequestBody ( Uses Consumes="MIMEType")
Note: MIME Means Multipurpose Internet Mail Extension.
you can find clear Explanation from https://www.tutorialspoint.com/html/mime_media_types.htmThank you. Simply explained and much needed.
Reply
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK