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

  • Study with Substance P

    Study with S

    31 Mayıs 2008
  • TheDailyTechDose

    TheDailyTech

    15 EKİM 2012
  • VOICE TV

    VOICE TV

    2 Aralık 2010