Get HTTP Response headers
using System;
using System.IO;
using System.Net;
public class TryHttpRequest {
public static void Main(String [] args) {
HttpWebRequest request =(HttpWebRequest)WebRequest.Create("http://www.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}\n",response.GetResponseHeader("Content-Length"));
}
}
Related examples in the same category