Csharp/C Sharp by API/System.Net/WebHeaderCollection

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

WebHeaderCollection.Count

<source lang="csharp">

using System; using System.IO; using System.Net; public class TryURL {

 public static void Main(String [] args) {
   WebClient client = new WebClient();
   client.BaseAddress = "http://www.nfex.ru";
   client.DownloadFile("www.nfex.ru", "index.htm");
   StreamReader input =new StreamReader(client.OpenRead("index.htm"));
   Console.WriteLine(input.ReadToEnd());
   Console.WriteLine
     ("Request header count: {0}", client.Headers.Count);
   WebHeaderCollection header = client.ResponseHeaders;
   Console.WriteLine
     ("Response header count: {0}", header.Count);
   for (int i = 0; i < header.Count; i++)
     Console.WriteLine("   {0} : {1}", 
                         header.GetKey(i), header[i]);
   input.Close();
 }

}


 </source>


WebHeaderCollection.GetKey

<source lang="csharp"> using System; using System.IO; using System.Net; public class TryURL {

 public static void Main(String [] args) {
   WebClient client = new WebClient();
   client.BaseAddress = "http://www.nfex.ru";
   client.DownloadFile("www.nfex.ru", "index.htm");
   StreamReader input =new StreamReader(client.OpenRead("index.htm"));
   Console.WriteLine(input.ReadToEnd());
   Console.WriteLine
     ("Request header count: {0}", client.Headers.Count);
   WebHeaderCollection header = client.ResponseHeaders;
   Console.WriteLine
     ("Response header count: {0}", header.Count);
   for (int i = 0; i < header.Count; i++)
     Console.WriteLine("   {0} : {1}", 
                         header.GetKey(i), header[i]);
   input.Close();
 }

}


 </source>