SORU
23 EYLÜL 2008, Salı


Http:/.../File Boyut olsun

Ben indirmeden önce bir http:/.../file boyutunu almak istiyorum. Dosyayı bir web sayfası, resim veya medya dosyası olabilir. Bu HTTP başlıkları ile yapılabilir mi? Nasıl sadece dosya header İndirebilirim?

CEVAP
23 EYLÜL 2008, Salı


Evet, konuşuyorsun HTTP Sunucusu varsayarak bu sağlar destekler:

System.Net.WebRequest req = System.Net.HttpWebRequest.Create("http://stackoverflow.com/robots.txt");
req.Method = "HEAD";
using (System.Net.WebResponse resp = req.GetResponse())
{
    int ContentLength;
    if(int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength))
    { 
        //Do something useful with ContentLength here 
    }
}

Eğer kullanarak KAFASINA yöntemi izin verilmez, ya da İçerik-Uzunluk Başlığı yok sunucu yanıt, tek yolu belirlemek için boyutu içeriğine sunucu için indirin. Bu özellikle güvenilir olmadığından, çoğu sunucu bu bilgileri içerir.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ExcelTutorials

    ExcelTutoria

    2 Mayıs 2009
  • H3Ctic (old channel)

    H3Ctic (old

    23 Mart 2011
  • superemposed

    superemposed

    25 Aralık 2007