Get HTTP Response headers

image_pdfimage_print
   

using System;
using System.IO;
using System.Net;

public class TryHttpRequest {
  public static void Main(String [] args) {
    HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://www.kutayzorlu.com/java2s/com");
    HttpWebResponse response =(HttpWebResponse)request.GetResponse();
    request.Accept = "text/plain";
    
    Console.WriteLine("Response headers");
    Console.WriteLine("  Protocol version: {0}",                                             response.ProtocolVersion);
    Console.WriteLine("  Status code: {0}",response.StatusCode);
    Console.WriteLine("  Status description: {0}",response.StatusDescription);
    Console.WriteLine("  Content encoding: {0}",response.ContentEncoding);
    Console.WriteLine("  Content length: {0}",response.ContentLength);
    Console.WriteLine("  Content type: {0}",response.ContentType);
    Console.WriteLine("  Last Modified: {0}",response.LastModified);
    Console.WriteLine("  Server: {0}", response.Server);
    Console.WriteLine("  Length using method: {0}
",response.GetResponseHeader("Content-Length"));
  
  }
}

           
          


This entry was posted in C# Network. Bookmark the permalink.