Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Распределённые приложения и сеть > Скачать часть файла (C#)


Автор: Nige 9.5.2006, 11:28
Подскажите, как в C# скачать часть большого файла (начиная с позиции X длиной Y) по протоколу http? 

Автор: vinegr 16.5.2006, 19:26
в смысле, какие заголовки НТТР надо задать?
Accept-Ranges: bytes
Content-Length:
Content-Range: bytes ВВВ-ЕЕЕ

если используешь класс System.Net.HttpWebRequest, то у него есть метод AddRange, который все это делает.
пример из МСДН
Код

// Create a New 'HttpWebRequest' object .
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
myHttpWebRequest.AddRange(50,150);    
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
// Display the contents of the page to the console.
Stream streamResponse=myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader( streamResponse );
Char[] readBuffer = new Char[256];
int count = streamRead.Read( readBuffer, 0, 256 );
Console.WriteLine("\nThe HTML contents of the page from 50th to 150 charaters are :\n  ");    
while (count > 0) 
{
    String outputData = new String(readBuffer, 0, count);
    Console.WriteLine(outputData);
    count = streamRead.Read(readBuffer, 0, 256);
}
// Release the response object resources.
streamRead.Close();
streamResponse.Close();
myHttpWebResponse.Close();


 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)