Пример #1
0
 static void Main()
 {
     using (MyClient client = new MyClient())
     {
         client.HeadOnly = true;
         string uri  = "http://www.google.com";
         byte[] body = client.DownloadData(uri);     // note should be 0-length
         string type = client.ResponseHeaders["content-type"];
         client.HeadOnly = false;
         // check 'tis not binary... we'll use text/, but could
         // check for text/html
         if (type.StartsWith(@"text/"))
         {
             string text = client.DownloadString(uri);
             Console.WriteLine(text);
         }
     }
 }
Пример #2
0
        private static string GetContent(String csvLink)
        {
            if (System.IO.File.Exists(csvLink))
                return System.IO.File.ReadAllText(csvLink);

            String content = "";
            using (MyClient client = new MyClient())
            {
                client.HeadOnly = true;
                string uri = csvLink;
                byte[] body = client.DownloadData(uri); // note should be 0-length
                string type = client.ResponseHeaders["content-type"];
                client.HeadOnly = false;
                // check 'tis not binary... we'll use text/, but could
                // check for text/html
                if (type.StartsWith(@"text/") || IsTextExtension(csvLink))
                {
                    client.HeadOnly = false;
                    content = client.DownloadString(uri);
                }
                else
                    throw new Exception(@"Dokumentet skal være tekst-baseret. Se den gratis demo for hjælp");
            }
            return content;
        }