Do I need a content type for http get requests?

As far as I understood there are two places where to set the content type:

  • The client sets a content type for the body he is sending to the server (eg for post)
  • The server sets a content type for the response.
  • Does this mean I don't have to or should not set a content type for all my get requests (client side). And if I can or should what content type would that be?

    Also I read in a few posts that the content type of the client specifies what type of content the client would like to receive. So maybe my point 1 is not right?


    According to the RFC 7231 section 3.1.5.5:

    A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" ([RFC2046], Section 4.5.1) or examine the data to determine its type.

    It means that the Content-Type HTTP header should be set only for PUT and POST requests.


    获取请求不应该具有内容类型,因为它们没有请求实体(即一个主体)


    GET requests can have "Accept" headers, which say which types of content the client understands. The server can then use that to decide which content type to send back.

    They're optional though.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

    链接地址: http://www.djcxy.com/p/22146.html

    上一篇: 编码POST数据?

    下一篇: 我需要http获取请求的内容类型吗?