是内容传输编码的HTTP头? [英] Is Content-Transfer-Encoding an HTTP header?

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

问题描述

我正在写返回一个base64-CN codeD上的PDF文件,所以我的计划是两个头添加到响应Web服务:

I'm writing a web service that returns a base64-encoded PDF file, so my plan is to add two headers to the response:

Content-Type: application/pdf
Content-Transfer-Encoding: base64

我的问题是:内容传输编码有效的HTTP标头?我想这可能仅仅是为MIME。如果不是这样,我应该怎么我的手艺HTTP响应重新present我正在返回一个base64-CN codeD PDF的事实呢?谢谢你。

My question is: Is Content-Transfer-Encoding a valid HTTP header? I think it might only be for MIME. If not, how should I craft my HTTP response to represent the fact that I'm returning a base64-encoded PDF? Thanks.

编辑:

它看起来像HTTP不支持这个头。从 RFC2616第14节

It looks like HTTP does not support this header. From RFC2616 Section 14:

请注意:虽然内容-MD5的定义是完全用于HTTP一样
  如RFC 1864年为MIME实体机构,有几种方法,其中
  内容-MD5以HTTP实体机构的应用不同于其
  应用MIME实体机构。其中之一是, HTTP,不像MIME,不
  不要使用内容传送编码
,并执行使用传输编码和
  内容编码。

Note: while the definition of Content-MD5 is exactly the same for HTTP as in RFC 1864 for MIME entity-bodies, there are several ways in which the application of Content-MD5 to HTTP entity-bodies differs from its application to MIME entity-bodies. One is that HTTP, unlike MIME, does not use Content-Transfer-Encoding, and does use Transfer-Encoding and Content-Encoding.

为我设定我的头以任何想法?谢谢你。

Any ideas for what I should set my headers to? Thanks.

编辑2

在许多的PHP参考手册页的评论中发现的code样本似乎表明,它实际上的有效的HTTP标头:

Many of the code samples found in the comments of this PHP reference manual page seem to suggest that it actually is a valid HTTP header:

<一个href=\"http://php.net/manual/en/function.header.php\">http://php.net/manual/en/function.header.php

推荐答案

根据 RFC 1341 (由 RFC 2045 过时):

一个内容传输编码头字段,它可以用来
  指定施加到数据以辅助编码
  允许它通过可具有邮件传输机制
  数据或字符集限制。

A Content-Transfer-Encoding header field, which can be used to specify an auxiliary encoding that was applied to the data in order to allow it to pass through mail transport mechanisms which may have data or character set limitations.

和更高版本:

许多内容类型这可以有效通过邮件运输
  重新presented,在他们的天然的格式,作为8位字符或
  二进制数据。这些数据不能对一些运输传送
  协议。例如,RFC 821限制邮件7位
  US-ASCII数据与1000字符行。

Many Content-Types which could usefully be transported via email are represented, in their "natural" format, as 8-bit character or binary data. Such data cannot be transmitted over some transport protocols. For example, RFC 821 restricts mail messages to 7-bit US-ASCII data with 1000 character lines.

有必要的,因此,以限定为一个标准的机制
  重新编码这些数据转换成7位短行格式。 (...)的
  内容传送编码字段用于指示的类型
  已在顺序被用于转化以重新present身体
  在运输可接受的方式。

It is necessary, therefore, to define a standard mechanism for re-encoding such data into a 7-bit short-line format. (...) The Content-Transfer-Encoding field is used to indicate the type of transformation that has been used in order to represent the body in an acceptable manner for transport.

既然你有一个Web服务,它没有任何共同之处与电子邮件,你不应该使用此标题。

Since you have a webservice, which has nothing in common with emails, you shouldn't use this header.

您可以使用内容编码头这表明传输的数据已经融为一体pressed(gzip的值)。

You can use Content-Encoding header which indicates that transferred data has been compressed (gzip value).

我认为你的情况

Content-Type: application/pdf

就足够了。此外,还可以设置的Content-Length 头,但在我看来,如果您正在构建web服务(这不是HTTP服务器/代理服务器)内容 - 类型就足够了。请记住,某些特定的头文件(如传输编码),如果不正确使用,可能会导致意外通信问题,所以如果你不是100%肯定的一些用法头 - 如果你真的需要与否 - 只是不使用它

is enough. Additionally, you can set Content-Length header, but in my opinion, if you are building webservice (it's not http server / proxy server) Content-Type is enough. Please bear in mind that some specific headers (e.g. Transfer-Encoding) if not used appropriately, may cause unexpected communication issues, so if you are not 100% sure about usage of some header - if you really need it or not - just don't use it.

这篇关于是内容传输编码的HTTP头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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