将HttpResponseMessage.Content数据(ReadAsStringAsync)限制为特定的最大大小

时间:2012-12-17 06:04:55

标签: c# asynchronous .net-4.5 dotnet-httpclient

我正在使用以下内容:

HttpClient client = new HttpClient();
HttpResponseMessage message = await client.GetAsync(myUrl);
String content = await message.Content.ReadAsStringAsync();

有没有办法限制通过HttpResponseMessage.Content下载多少?如果我不信任URL,并且URL实际反馈100 GB,那么这可能会带来麻烦...我基本上想将此限制为可配置的字节数 - 如果有更多,我不会想要它! :)谢谢!

1 个答案:

答案 0 :(得分:1)

也许这个链接会有所帮助:

http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.maxresponsecontentbuffersize.aspx

HttpClient.MaxResponseContentBufferSize