简体   繁体   中英

Limit HttpResponseMessage.Content data (ReadAsStringAsync) to specific maximum size

I'm using the following:

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

Is there a way to limit how much is downloaded via the HttpResponseMessage.Content? If I don't trust the URL, and the URL actually feeds back 100 GB, then this could spell trouble... I'd basically like to limit this to a configurable number of bytes - and if there's more, I don't want it! :) Thanks!

Maybe this link will help:

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

HttpClient.MaxResponseContentBufferSize

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM