Get HTTP Response headers : Web Request Response « Network « C# / C Sharp






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

1.Uses WebRequest and WebResponse. Tests use HTTP and the file protocol
2.Get HTTP Request Headers
3.Provides a response from a Uniform Resource Identifier (URI).
4.Gets or sets the content length of data being received.
5.Returns the data stream from the Internet resource.
6.Gets a collection of header name-value pairs associated with this request.
7.Boolean value that indicates whether mutual authentication occurred.
8.Gets the URI of the Internet resource that actually responded to the request.
9.Create a new instance of the WebRequest class.
10.Initializes a new WebRequest instance for the specified URI scheme.
11.Create WebRequest instance for the specified URI scheme.
12.Gets or sets the network credentials used for authenticating the request with the Internet resource.
13.Returns a response to an Internet request.
14.Gets or sets the collection of header name/value pairs associated with the request.
15.Indicates whether to pre-authenticate the request.
16.Gets the URI of the Internet resource associated with the request.
17.Send Request By Post