问题
I have a 10 mb file at an URI I download it with the following codes.
WebClient wc = new WebClient(); string file = wc.DownloadString(http://www......com);
Can I download certain sizes of this file, such as 1 mb, 5 mb. not whole 10 mb. ? Then stop downloading?
Thanks.
回答1:
Add the HTTP Range header in your request. Note that this will only work if the server supports it.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more information about it
回答2:
you can use httpwebrequest to getresponse. load whatever lines you want. check: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse%28v=vs.71%29.aspx
the example use ReadToEnd. you can use other methods to read just part of it.
来源:https://stackoverflow.com/questions/12976047/webclient-downloadstringuri-uri-has-10-mb-file-can-i-download-a-certain-size