我需要http获取请求的内容类型吗? [英] Do I need a content type for http get requests?

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

问题描述

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


  1. 客户端为主体设置内容类型他将发送到服务器(例如发送邮件)

  2. 服务器设置响应的内容类型。

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

另外我在几篇文章中读到,客户端的内容类型指定客户端的内容类型喜欢接受。所以也许我的观点1是不正确的?根据 org / html / rfc7231#section-3.1.1.5rel =noreferrer> RFC 7231 section 3.1.5.5


除非发送者未知封装表示的目标媒体类型,否则生成包含有效内容主体的消息的发件人应该在该消息中生成一个Content-Type标头字段如果不存在内容类型标题字段,则收件人可以采用媒体类型为application / octet-stream( [RFC2046],4.5.1节)或检查数据以确定其类型。


这意味着只应为 PUT Content-Type HTTP标头c>和 POST 请求。


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

  1. The client sets a content type for the body he is sending to the server (e.g. for post)
  2. 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.

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

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