标签: chunked

HttpWebRequest chunked/async POST

嗨,我想将一些动态生成的内容上传到我的网络API.在客户端我使用HttpWebRequest.数据应该上传同步,我想写入流AFTER(!)我执行了HTTP请求.

(从服务器到客户端它确实工作正常,但从客户端到服务器我得到一些例外).

客户端实现如下:

HttpWebRequest httpWebRequest = HttpWebRequest.Create(myUrl) as HttpWebRequest;
httpWebRequest.Method = "POST";
httpWebRequest.Headers["Authorization"] = "Basic " + ... ;
httpWebRequest.PreAuthenticate = true;

httpWebRequest.SendChunked = true;
//httpWebRequest.AllowWriteStreamBuffering = false; //does not help...
httpWebRequest.ContentType = "application/octet-stream";
Stream st = httpWebRequest.GetRequestStream();

Task<WebResponse> response = httpWebRequest.GetResponseAsync();

// NOW: Write after GetResponse()

var b = Encoding.UTF8.GetBytes("Test1");
st.Write(b, 0, b.Length);

b = Encoding.UTF8.GetBytes("Test2");
st.Write(b, 0, b.Length);

b = Encoding.UTF8.GetBytes("Test3");
st.Write(b, 0, b.Length);

st.Close();

var x = response.Result;
Stream resultStream = x.GetResponseStream();
//do some output...
Run Code Online (Sandbox Code Playgroud)

我在stream.write()上得到异常(NotSupportedException:流不支持并发IO读或写操作.).

为什么我这里有例外.有时第一次写入worke而后期写入会抛出异常.在开始时,stream.CanWrite属性为true,但在第一次或第二次或第四次写入后,它变为false …

c# asynchronous stream httpwebrequest chunked

6
推荐指数
1
解决办法
7316
查看次数

如何使 Apache mod_deflate 和 Transfer-encoding : Chunked 一起工作?

我正在尝试在我们的网站上使用大管道概念。这意味着尝试以块的形式发送响应,而不是整体发送响应,以便用户感觉该页面很快。我通过在 java 中的响应对象上使用flushBuffer方法成功地做到了这一点。但是现在,当我尝试使用 apache mod_deflate 模块压缩内容时,分块丢失了。

这是 apache 用于压缩内容的配置

**

开始 mod_deflate 配置

DeflateBufferSize 100
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
DeflateFilterNote Input input_info
DeflateFilterNote Output output_info
DeflateFilterNote Ratio ratio_info
LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
CustomLog /var/log/httpd/deflate_log deflate
Run Code Online (Sandbox Code Playgroud)

结束 mod_deflate 配置**

这是apache中打开deflate时的响应头

连接:保持活动
内容编码:gzip
内容长度:7916
内容类型:text/html;字符集 = UTF-8
日期:2012 年 1 月 27 日星期五 20:11:11 GMT
保持活动:超时 = 300,最大值 = 3997
服务器:Apache
Vary:Accept-Encoding

apache 中关闭 deflate 时的响应头

连接:保持活动
内容类型:text/html;字符集 = …

apache mod-deflate chunked

5
推荐指数
1
解决办法
7232
查看次数

使用angularjs $ http处理分块响应

我发现最近的回复很混乱。我同意大多数时候我们都希望做出全面回应。但是,如果我想处理分块响应,该怎么办。

我将如何使用$ http服务呢?

http chunked angularjs

5
推荐指数
1
解决办法
4262
查看次数

urllib2 python(Transfer-Encoding:chunked)

我使用以下python代码下载html页面:

response = urllib2.urlopen(current_URL)
msg = response.read()  
print msg
Run Code Online (Sandbox Code Playgroud)

对于像这样的页面,它会打开网址而不会出现错误,但只打印部分html页面!

在以下行中,您可以找到html页面的http标头.我认为这个问题是由于"Transfer-Encoding:chunked"造成的.

似乎urllib2只返回第一个块!我在阅读其余的块时遇到了困难.我怎么能读剩下的块?

Server: nginx/1.0.5
Date: Wed, 27 Feb 2013 14:41:28 GMT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: route=c65b16937621878dd49065d7d58047b2; Path=/
Set-Cookie: JSESSIONID=EE18E813EE464664EA64086D5AE9A290.tpdjo13v_3; Path=/
Pragma: No-cache
Cache-Control: no-cache,no-store,max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Vary: Accept-Encoding
Content-Language: fr
Run Code Online (Sandbox Code Playgroud)

python urllib2 chunked transfer-encoding

5
推荐指数
1
解决办法
2323
查看次数

通过php上传大文件(0-5GB)的有效方法

我一直在寻找一个好的方法,并把头撞在墙上。

在一个文件共享服务项目中,我被指派确定上传大文件的最佳方法。

在 stackoverflow 和其他论坛上搜索了很多问题后,我得到了以下结果:

  1. 增加脚本最大执行时间以及允许的最大文件大小

    这个案子确实不太合适。每次通过普通宽带连接(1mbps-2mbps)上传文件时几乎都会超时。即使上传完成后执行PHP脚本,仍然不能保证上传不会超时。

  2. 分块上传。

    虽然我有点明白我应该在这里做什么,但我感到困惑的是,假设正在上传一个 1GB 的文件,我正在以 2MB 的块读取它,但如果上传很慢, php 脚本执行将超时并给出错误。

  3. 使用 Java 和 Perl 等其他语言?

    使用java或perl处理文件上传真的有效吗?

客户端使用的方法不是这里的问题,因为我们将发布一个客户端 SDK,并且可以在其中实现我们选择的方法。客户端和服务器端的实现都将由我们决定。

根据您的观点,考虑到内存使用效率应该很高,并且可能有很多并发上传,哪种方法应该是最好的方法?

Dropbox 和类似的云存储服务如何处理大文件上传并保持快速上传?

php apache upload chunked large-file-upload

5
推荐指数
1
解决办法
2万
查看次数

使用AngularJs处理Play scala发送的分块数据

我送chunked dataPlay Scala 2.2像这样的客户端:Ok.chunked(data)

我想在客户端提供它们时尽快使用它们.如果我只是获取数据并打印它们.success,它们会同时打印,即收到最后一个数据.

如何在收到后立即打印出来?我必须用websockets吗?

scala chunked http-chunked angularjs playframework-2.2

5
推荐指数
1
解决办法
1312
查看次数

Java HTTP server sending chunked response

I am working on a Java application which has a built in HTTP server, at the moment the server is implemented using ServerSocketChannel, it listens on port 1694 for requests:

        msvrCh = ServerSocketChannel.open();
        msvrCh.socket().bind(new InetSocketAddress(mintPort));
        msvrCh.configureBlocking(false);
Run Code Online (Sandbox Code Playgroud)

A thread is installed to manage requests and responses:

        Thread thrd = new Thread(msgReceiver);
        thrd.setUncaughtExceptionHandler(exceptionHandler);
        thrd.start();
Run Code Online (Sandbox Code Playgroud)

The thread is quite simple:

        Runnable msgReceiver = new Runnable() {
            @Override
            public void run() {
                try{
                    while( !Thread.interrupted() ) {
    //Sleep a short period between checks for …
Run Code Online (Sandbox Code Playgroud)

java http chunked chunked-encoding http-chunked

5
推荐指数
1
解决办法
7190
查看次数

XMLHttpRequest分块响应,仅读取进行中的最后一个响应

我正在将来自NodeJS应用程序的分块数据发送回浏览器。这些块实际上是json字符串。我遇到的问题是,每次onprogress调用该函数时,它都会添加一串完整的数据。意味着将第二个响应块附加到第一个响应块上,依此类推。我只想获得“立即”收到的数据块。

这是代码:

    console.log("Start scan...");
    var xhr = new XMLHttpRequest();
    xhr.responseType = "text";
    xhr.open("GET", "/servers/scan", true);
    xhr.onprogress = function () {
        console.log("PROGRESS:", xhr.responseText);
    }
    xhr.send();
Run Code Online (Sandbox Code Playgroud)

因此,实际上,xhr.responseText的内容在第三个响应到来时还包含第一个和第二个响应的响应文本。我检查了服务器正在发送的内容,看来那里没有问题。将Node与Express结合使用,并发送res.send("...")几次。标头也设置如下:

res.setHeader('Transfer-Encoding', 'chunked');
res.setHeader('X-Content-Type-Options', 'nosniff');
res.set('Content-Type', 'text/json');
Run Code Online (Sandbox Code Playgroud)

javascript xmlhttprequest chunked node.js

5
推荐指数
1
解决办法
4063
查看次数

为什么有些服务器在最后一个块长度为零后不使用 CRLF?

我正在使用 HTTP 请求工具(类似于 cURL)并且遇到服务器响应问题。或者我对 HTTP 1.1 和分块数据的 RFC 的理解。

我所看到的是分块数据应采用以下格式:

4\r\n
Wiki\r\n
5\r\n
pedia\r\n
e\r\n
 in\r\n\r\nchunks.\r\n
0\r\n
\r\n
Run Code Online (Sandbox Code Playgroud)

我实际看到的是以下内容:

4\r\n
Wiki\r\n
5\r\n
pedia\r\n
e\r\n
 in\r\n\r\nchunks.\r\n
0
Run Code Online (Sandbox Code Playgroud)

换句话说,我测试过的少数服务器在 0.. 之后不再发送数据。不是 CRLF,更不用说 CRLFCRLF。

如果没有正确的分块标签格式,我们怎么知道这是分块数据的结尾?超时发生在 0 之后寻找 CRLF,这还不够。

http chunked chunked-encoding

5
推荐指数
1
解决办法
1464
查看次数

Dropzone JS with Flask:分块并行上传

我正在尝试使用 dropzone js 和 Flask 作为后端。拖放区配置:

<form method="POST" action='/process_chunk' class="dropzone dz-clickable"
     id="dropper" enctype="multipart/form-data">
</form>

<script type="application/javascript">
   Dropzone.options.dropper = {
       {# https://gitlab.com/meno/dropzone/wikis/faq#chunked-uploads #}
       paramName: 'file',
       acceptedFiles: '.csv',
       chunking: true,
       forceChunking: true,
       chunkSize: 100000, // bytes
       parallelChunkUploads: true,
       maxFilesize: 1025, // megabytes
</script>
Run Code Online (Sandbox Code Playgroud)

我的烧瓶后端如下所示

@app.route('/process_chunk', methods=['POST'])
def process_chunk():
    current_chunk = int(request.form['dzchunkindex'])

    file = request.files['file']
    save_path = os.path.join(app.config['DATA_DIR'], file.filename)

    try:
        with open(save_path, 'ab+') as f:
            # Goto the offset, aka after the chunks we already wrote
            f.seek(int(request.form['dzchunkbyteoffset']))
            f.write(file.stream.read())
    except OSError:
        # log.exception will …
Run Code Online (Sandbox Code Playgroud)

python upload chunked flask dropzone.js

5
推荐指数
1
解决办法
1396
查看次数