Я пытаюсь загрузить zip-папку с URL-адреса. URL-адрес указывает на библиотеку в Sharepoint, содержащую набор документов. Если URL-адрес вставлен в браузер, он загружает zip-файл. Пытаясь сделать то же самое из кода, я могу загрузить только 32426 байт. Я попробовал два подхода: один DownloadDataAsync() с использованием WebClient, а другой - WebRequest и ответ. Оба они читают только 32426 байт, тогда как zip-папка занимает около 6 МБ.
using (var Webclient1 = new WebClient())
{
Webclient1.Headers.Add("Accept: text/html, application/xhtml+xml, */*");
Webclient1.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
byte[] data = null;
Webclient1.DownloadDataCompleted +=
delegate(object sender, DownloadDataCompletedEventArgs e)
{
data = e.Result;
};
Webclient1.DownloadDataAsync(uri);
while (Webclient1.IsBusy)
{
System.Threading.Thread.Sleep(10000);
}
var len = data.Length;
}
Использование HttpRequest и ответа
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
//request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Accept = @"text/html, application/xhtml+xml, */*";
request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)";
request.Timeout = 1000000;
using (var response = request.GetResponse())
{
MemoryStream stream2 = new MemoryStream();
var stream = response.GetResponseStream();
stream.CopyTo(stream2);
return stream2.ToArray();
}
Оба читают неполный контент.