<legend id='kOAlk'><style id='kOAlk'><dir id='kOAlk'><q id='kOAlk'></q></dir></style></legend>
  • <i id='kOAlk'><tr id='kOAlk'><dt id='kOAlk'><q id='kOAlk'><span id='kOAlk'><b id='kOAlk'><form id='kOAlk'><ins id='kOAlk'></ins><ul id='kOAlk'></ul><sub id='kOAlk'></sub></form><legend id='kOAlk'></legend><bdo id='kOAlk'><pre id='kOAlk'><center id='kOAlk'></center></pre></bdo></b><th id='kOAlk'></th></span></q></dt></tr></i><div id='kOAlk'><tfoot id='kOAlk'></tfoot><dl id='kOAlk'><fieldset id='kOAlk'></fieldset></dl></div>
  • <tfoot id='kOAlk'></tfoot>
      <bdo id='kOAlk'></bdo><ul id='kOAlk'></ul>

      1. <small id='kOAlk'></small><noframes id='kOAlk'>

        未知内容长度的 HTTP 标头

        时间:2023-06-03

        <i id='emsnO'><tr id='emsnO'><dt id='emsnO'><q id='emsnO'><span id='emsnO'><b id='emsnO'><form id='emsnO'><ins id='emsnO'></ins><ul id='emsnO'></ul><sub id='emsnO'></sub></form><legend id='emsnO'></legend><bdo id='emsnO'><pre id='emsnO'><center id='emsnO'></center></pre></bdo></b><th id='emsnO'></th></span></q></dt></tr></i><div id='emsnO'><tfoot id='emsnO'></tfoot><dl id='emsnO'><fieldset id='emsnO'></fieldset></dl></div>
            <legend id='emsnO'><style id='emsnO'><dir id='emsnO'><q id='emsnO'></q></dir></style></legend>
          • <small id='emsnO'></small><noframes id='emsnO'>

              <bdo id='emsnO'></bdo><ul id='emsnO'></ul>
              1. <tfoot id='emsnO'></tfoot>
                  <tbody id='emsnO'></tbody>

                1. 本文介绍了未知内容长度的 HTTP 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我目前正在尝试在转码过程后将内容流式传输到网络.这通常可以通过将二进制文件写入我的 Web 流来正常工作,但是某些浏览器(特别是 IE7、IE8)不喜欢在 HTTP 标头中没有定义 Content-Length.我相信有效"的标题应该有这个设置.

                  I am currently trying to stream content out to the web after a trans-coding process. This usually works fine by writing binary out to my web stream, but some browsers (specifically IE7, IE8) do not like not having the Content-Length defined in the HTTP header. I believe that "valid" headers are supposed to have this set.

                  当您的 Content-Length 未知时,将内容流式传输到网络的正确方法是什么?转码过程可能需要一段时间,所以我想在它完成后开始流式传输.

                  What is the proper way to stream content to the web when you have an unknown Content-Length? The trans-coding process can take awhile, so I want to start streaming it out as it completes.

                  推荐答案

                  尝试将它们与 传输编码: 分块.维基百科中的更多详细信息.

                  Try sending them in chunks along with Transfer-Encoding: chunked. More details in wikipedia.

                  更新根据评论,这是一个示例,Java 中的ChunkedOutputStream"可能如下所示:

                  Update as per the comments, here's an example how a "ChunkedOutputStream" in Java may look like:

                  package com.stackoverflow.q2395192;
                  
                  import java.io.IOException;
                  import java.io.OutputStream;
                  
                  public class ChunkedOutputStream extends OutputStream {
                  
                      private static final byte[] CRLF = "
                  ".getBytes();
                      private OutputStream output = null;
                  
                      public ChunkedOutputStream(OutputStream output) {
                          this.output = output;
                      }
                  
                      @Override
                      public void write(int i) throws IOException {
                          write(new byte[] { (byte) i }, 0, 1);
                      }
                  
                      @Override
                      public void write(byte[] b, int offset, int length) throws IOException {
                          writeHeader(length);
                          output.write(CRLF, 0, CRLF.length);
                          output.write(b, offset, length);
                          output.write(CRLF, 0, CRLF.length);
                      }
                  
                      @Override
                      public void flush() throws IOException {
                          output.flush();
                      }
                  
                      @Override
                      public void close() throws IOException {
                          writeHeader(0);
                          output.write(CRLF, 0, CRLF.length);
                          output.write(CRLF, 0, CRLF.length);
                          output.close();
                      }
                  
                      private void writeHeader(int length) throws IOException {
                          byte[] header = Integer.toHexString(length).getBytes();
                          output.write(header, 0, header.length);
                      }
                  
                  }
                  

                  ...基本上可以用作:

                  ...which can basically be used as:

                  OutputStream output = new ChunkedOutputStream(response.getOutputStream());
                  output.write(....);
                  

                  您在源代码中看到,每个数据块都存在一个标头,该标头表示十六进制数据的长度,一个 CRLF,实际数据和一个 CRLF.流的结尾由表示 0 长度和两个 CRLF 的标头表示.

                  You see in the source, every chunk of data exist of a header which represents the length of data in hex, a CRLF, the actual data and a CRLF. The end of the stream is represented by a header denoting a 0 length and two CRLFs.

                  注意:尽管有示例,但您实际上不需要在基于 JSP/Servlet 的 Web 应用程序中需要它.每当响应中没有设置内容长度时,webcontainer 会自动以块的形式传输它们.

                  Note: despite the example, you actually do not need it in a JSP/Servlet based webapplication. Whenever the content length is not set on a response, the webcontainer will automatically transfer them in chunks.

                  这篇关于未知内容长度的 HTTP 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:c#中布尔值的二进制表示是什么 下一篇:如何在 C# 中获取浮点数的 IEEE 754 二进制表示

                  相关文章

                  最新文章

                  <small id='7gCKu'></small><noframes id='7gCKu'>

                  1. <legend id='7gCKu'><style id='7gCKu'><dir id='7gCKu'><q id='7gCKu'></q></dir></style></legend>
                    • <bdo id='7gCKu'></bdo><ul id='7gCKu'></ul>
                    <tfoot id='7gCKu'></tfoot>

                      <i id='7gCKu'><tr id='7gCKu'><dt id='7gCKu'><q id='7gCKu'><span id='7gCKu'><b id='7gCKu'><form id='7gCKu'><ins id='7gCKu'></ins><ul id='7gCKu'></ul><sub id='7gCKu'></sub></form><legend id='7gCKu'></legend><bdo id='7gCKu'><pre id='7gCKu'><center id='7gCKu'></center></pre></bdo></b><th id='7gCKu'></th></span></q></dt></tr></i><div id='7gCKu'><tfoot id='7gCKu'></tfoot><dl id='7gCKu'><fieldset id='7gCKu'></fieldset></dl></div>