我是否需要 HTTP GET 请求的内容类型标头? [英] Do I need a content-type header for HTTP GET requests?

查看:38
本文介绍了我是否需要 HTTP GET 请求的内容类型标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,有两个地方可以设置内容类型:

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

  1. 客户端为他发送到服务器的正文设置内容类型(例如,用于发布)
  2. 服务器为响应设置内容类型.

这是否意味着我不必或不应该为我的所有获取请求(客户端)设置内容类型.如果我可以或应该是什么内容类型?

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?

我还在一些帖子中读到,客户端的内容类型指定了客户端想要接收的内容类型.所以也许我的第 1 点是不对的?

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?

推荐答案

根据 RFC 7231 第 3.1.5.5 节:

生成包含有效负载正文的消息的发送者应该在该消息中生成一个 Content-Type 标头字段,除非发送者不知道封闭表示的预期媒体类型.如果 Content-Type 头域不存在,接收者可以假设媒体类型为application/octet-stream";([RFC2046],第 4.5.1 节)或检查数据以确定其类型.

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.

这意味着 Content-Type HTTP 头应该只为 PUTPOST 请求设置.

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

这篇关于我是否需要 HTTP GET 请求的内容类型标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆