超过HttpClient的缓存大小限制 [英] HttpClient buffer size limit exceeded

查看:4428
本文介绍了超过HttpClient的缓存大小限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的客户端来获取存储在我的雨燕对象存储特定文件,可以throught REST API访问的一些信息。在斯威夫特HEAD方法和URL导致指定的对象,返回它包含在HTML响应的元数据(哈希值,时间戳等)(没有内容)的标题。

I am using my client to get some info about a certain file stored in my Swift Object Storage which can be accessed throught REST Api. In Swift the HEAD method and url leading to specified object returns it's metadata (hash, timestamp, etc) contained in HTML response's (has NO CONTENT) headers.

我的code完美的作品时,文件大小为< 2GB。我得到的Htt presponseMessage,我能够解析它所需的数据,但是当我问文件> 2GB我得到异常:无法写入的字节数比配置的最大缓冲区大小的缓冲区:2147483647。

My code works perfectly when file size is < 2GB. I get HttpResponseMessage and I am able to parse it for required data, but when I ask for file > 2GB I get exception : "Cannot write more bytes to the buffer than the configured maximum buffer size: 2147483647".

据我所知,这HttpClient的财产MaxResponseContentBufferSize不能设置值> 2GB,但我不希望得到它的内容。这是一些bug或者是有一些更好的方法来解决这个问题?

I understand, that HttpClient property MaxResponseContentBufferSize cannot be set to value > 2GB, but I don't want to get it's content. Is this some bug or is there some better way to solve this?

public HttpResponseMessage FileCheckResponse(string objectName)
   {
        //create url which will be appended to HttpClient (m_client)
        string requestUrl = RequestUrlBuilder(m_containerName, objectName);
        //create request message with Head method
        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Head, requestUrl);
        //exception thrown here... 
        HttpResponseMessage response = m_client.SendAsync(request).Result;            

        return response;
    }

当试图执行使用开发HTTP客户端(Chrome扩展)我有没有问题同样的动作。看来,Content-Length头使得它不可行。下面是从开发HTTP客户端的输出:

When trying to perform same action using Dev HTTP Client (Chrome extension) I have no problem. It seems that Content-Length header makes it unfeasible. Here is the output from Dev HTTP Client:

Content-Length: 3900762112
Accept-Ranges: bytes
Last-Modified: Fri, 06 Sep 2013 16:24:30 GMT
Etag: da4392bdb5c90edf31c14d008570fb95
X-Timestamp: 1378484670.87557
Content-Type: application/octet-stream
Date: Tue, 10 Sep 2013 13:25:27 GMT
Connection: keep-alive

我会很高兴的任何想法! 谢谢

I will be glad for any ideas! Thank you

首先 - 感谢达雷尔Mirrel,谁在几秒钟内解决了我整整一天的问题:) 我只是需要编辑code一行由那里得到的反应将HttpCompletitionOption:

First - thanks to Darrel Mirrel, who solved my whole day problem in few seconds :) I just needed to edit one line in code by adding HttpCompletitionOption where response is obtained:

HttpResponseMessage response = m_client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result;

选项ResponseHeaderRead告诉客户尽快头读取完成操作withnout阅读邮件的内容。

The option ResponseHeaderRead tells the client to finish operation as soon as Headers are read withnout reading content of the message.

推荐答案

使用的SendAsync重载,允许你指定HttpCompletionOptions。有了这个,你可以告诉HttpClient的不创建缓冲区的响应内容。

Use the SendAsync overload that allows you to specify the HttpCompletionOptions. With this you can tell HttpClient not to create a buffer for the response contents.

这篇关于超过HttpClient的缓存大小限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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