System.Net.HttpWebResponse Class

Assembly: System.dll
Namespace: System.Net
Summary
Provides an HTTP-specific implementation of the WebResponse class.
C# Syntax:
[Serializable]
public class HttpWebResponse : WebResponse
Remarks
The HttpWebResponse class contains support for the properties and methods included in WebResponse with additional elements that enable the user to interact directly with the HTTP protocol.

You should never directly create an instance of the HttpWebResponse class. Instead, use the instance returned by a call to HttpWebRequest.GetResponse.

Common header information returned from the Internet resource is exposed as properties of the class. See the following table for a complete list. Other headers can be read from the HttpWebResponse.Headers property as name/value pairs.

The following table shows the common HTTP headers that are available through properties of the HttpWebResponse class.



Header Property
Content-Encoding HttpWebResponse.ContentEncoding
Content-Length HttpWebResponse.ContentLength
Content-Type HttpWebResponse.ContentType
Last-Modified HttpWebResponse.LastModified
Server HttpWebResponse.Server

The contents of the response from the Internet resource are returned as a Stream by calling the HttpWebResponse.GetResponseStream method.

Example
The following example returns an HttpWebResponse from an HttpWebRequest:
 HttpWebRequest HttpWReq = 
 (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
 
 HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
 // Insert code that uses the response object.
 HttpWResp.Close();

    
See also:
System.Net Namespace | WebResponse

System.Net.HttpWebResponse Member List:

Public Properties
CharacterSet Read-only

Gets the character set of the response.
ContentEncoding Read-only

Gets the method used to encode the body of the response.
ContentLength Read-only

Overridden:
Gets the length of the content returned by the request.
ContentType Read-only

Overridden:
Gets the content type of the response.
Cookies Read-write

Gets or sets the cookies associated with this request.
Headers Read-only

Overridden:
Gets the headers associated with this response from the server.
LastModified Read-only

Gets the last date and time that the contents of the response were modified.
Method Read-only

Gets the method used to return the response.
ProtocolVersion Read-only

Gets the version of the HTTP protocol used in the response.
ResponseUri Read-only

Overridden:
Gets the URI of the Internet resource that responded to the request.
Server Read-only

Gets the name of the server that sent the response.
StatusCode Read-only

Gets the status of the response.
StatusDescription Read-only

Gets the status description returned with the response.
Public Methods
Close Overridden:
Closes the response stream.
CreateObjRef
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.CreateObjRef


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode Overridden:
GetLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.GetLifetimeService


Retrieves the current lifetime service object that controls the lifetime policy for this instance.
GetResponseHeader Gets a specified header contents that was returned with the response.
GetResponseStream Overridden:
Gets the stream used to read the body of the response from the server.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
InitializeLifetimeService
(inherited from System.MarshalByRefObject)
See base class member description: System.MarshalByRefObject.InitializeLifetimeService


Obtains a lifetime service object to control the lifetime policy for this instance.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Constructors
ctor #1 Initializes a new instance of the HttpWebResponse class from the specified SerializationInfo and StreamingContext instances.
Protected Methods
Dispose
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Net.HttpWebResponse Member Details

ctor #1
Summary
Initializes a new instance of the HttpWebResponse class from the specified SerializationInfo and StreamingContext instances.
C# Syntax:
protected HttpWebResponse(
   SerializationInfo serializationInfo,
   StreamingContext streamingContext
);
Parameters:

serializationInfo

A SerializationInfo containing the information required to serialize the new HttpWebRequest.

streamingContext

A StreamingContext containing the source of the serialized stream associated with the new HttpWebRequest.

Remarks
This constructor implements the ISerializable interface for the HttpWebRequest class.
See also:
ISerializable

Return to top


Property: CharacterSet (read-only)
Summary
Gets the character set of the response.
C# Syntax:
public string CharacterSet {get;}
Remarks
The HttpWebResponse.CharacterSet property contains a value describing the character set of the response. This character set information is taken from the header returned with the response.

Return to top


Property: ContentEncoding (read-only)
Summary
Gets the method used to encode the body of the response.
C# Syntax:
public string ContentEncoding {get;}
Remarks
The HttpWebResponse.ContentEncoding property contains the value of the Content-Encoding header returned with the response.

Return to top


Overridden Property: ContentLength (read-only)
Summary
Gets the length of the content returned by the request.
C# Syntax:
public override long ContentLength {get;}
Remarks
The HttpWebResponse.ContentLength property contains the value of the Content-Length header returned with the response. If the Content-Length header is not set in the response, HttpWebResponse.ContentLength is set to the value -1.
Example
The following example uses HttpWebResponse.ContentLength to determine the length of the response content.
				Stream receiveStream = myHttpWebResponse.GetResponseStream();
        		Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
        		StreamReader readStream = new StreamReader( receiveStream, encode );
				
        		Console.WriteLine("\r\nResponse stream received.");
				char[] read = new char[256];
        			
				int count = readStream.Read( read, 0, 256 );
        			Console.WriteLine("\nText retrieved from the URL follows:\r\n");

				int index = 0;
				while (index < myHttpWebResponse.ContentLength)
				{
    				// Dumps the 256 characters on a string and displays the string to the console.
					String str = new String(read, 0, count);
					Console.WriteLine(str);
					index += count;
					count = readStream.Read(read, 0, 256);
				}
				// Releases the resources of the Stream.
				receiveStream.Close();
				Console.WriteLine("");
				}
				// Releases the resources of the response.
  				myHttpWebResponse.Close();
				

    

Return to top


Overridden Property: ContentType (read-only)
Summary
Gets the content type of the response.
C# Syntax:
public override string ContentType {get;}
Remarks
The HttpWebResponse.ContentType property contains the value of the Content-Type header returned with the response.
Example
The following example determines the content type and prints it to the screen.
	try 
 		  {	
			HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
			HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 

			char seperator = '/';
			String contenttype = myHttpWebResponse.ContentType;
			// Retrieves the text if the content type is of text/html.
			String maintype = contenttype.Substring(0,contenttype.IndexOf(seperator));
			// Displays only text type.
			if (String.Compare(maintype,"text") == 0) 
				{
				Console.WriteLine("\n Content type is text.");

	. . . 
				Stream receiveStream = myHttpWebResponse.GetResponseStream();
        		Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
        		StreamReader readStream = new StreamReader( receiveStream, encode );
				
        		Console.WriteLine("\r\nResponse stream received.");
				char[] read = new char[256];
        			
				int count = readStream.Read( read, 0, 256 );
        			Console.WriteLine("\nText retrieved from the URL follows:\r\n");

				int index = 0;
				while (index < myHttpWebResponse.ContentLength)
				{
    				// Dumps the 256 characters on a string and displays the string to the console.
					String str = new String(read, 0, count);
					Console.WriteLine(str);
					index += count;
					count = readStream.Read(read, 0, 256);
				}
				// Releases the resources of the Stream.
				receiveStream.Close();
				Console.WriteLine("");
				}
				// Releases the resources of the response.
  				myHttpWebResponse.Close();
				

    

Return to top


Property: Cookies (read-write)
Summary
Gets or sets the cookies associated with this request.
C# Syntax:
public CookieCollection Cookies {get; set;}
Remarks
The HttpWebResponse.Cookies property provides an instance of the CookieCollection class holding the cookies associated with this response.

If the HttpWebRequest.CookieContainer property of the associated HttpWebRequest is null, the HttpWebResponse.Cookies property will also be null. Any cookie information sent by the server will be available in the HttpWebResponse.Headers property, however.

Example
The following example displays the name of all cookies associated with this HttpWebResponse.
	try {	
	          HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
                 HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
                 CookieCollection myCookieCollection = myHttpWebResponse.Cookies;
                 for (int i = 0; i < myCookieCollection.Count; i++){
                      Console.WriteLine(myCookieCollection[i]);
                 }
                 myHttpWebResponse.Close();
       } 
	catch(WebException e) {
            Console.WriteLine("\r\nWebException Raised. The following error occured : {0}",e.Status); 
      }

    
See also:
CookieContainer

Return to top


Overridden Property: Headers (read-only)
Summary
Gets the headers associated with this response from the server.
C# Syntax:
public override WebHeaderCollection Headers {get;}
Remarks
The HttpWebResponse.Headers property is a collection of name/value pairs containing the HTTP header values returned with the response. Common header information returned from the Internet resource is exposed as properties of the HttpWebResponse class. The following table lists common headers that the API exposes as properties.

Header Property
Content-Encoding HttpWebResponse.ContentEncoding
Content-Length HttpWebResponse.ContentLength
Content-Type HttpWebResponse.ContentType
Last-Modified HttpWebResponse.LastModified
Server HttpWebResponse.Server
Example
The following example writes the contents of all of the response headers to the console.
				// Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				// Sends the HttpWebRequest and waits for response.
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				                        
				// Displays all the headers present in the response received from the URI.
				Console.WriteLine("\r\nThe following headers were received in the response:");
				// Displays each header and it's key associated with the response.
				for(int i=0; i < myHttpWebResponse.Headers.Count; ++i)  
					Console.WriteLine("\nHeader Name:{0}, Value :{1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]); 
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 

    

Return to top


Property: LastModified (read-only)
Summary
Gets the last date and time that the contents of the response were modified.
C# Syntax:
public DateTime LastModified {get;}
Remarks
The HttpWebResponse.LastModified property contains the value of the Last-Modified header received with the response. The date and time are assumed to be local time.
Example
This example creates an HttpWebRequest and queries for a response. This example then checks if the entity requested had been modified any time today.
            Uri myUri = new Uri(url);
				// Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); 
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
				if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
					Console.WriteLine("\r\nRequest succeeded and the requested information is in the response , Description : {0}",
										myHttpWebResponse.StatusDescription);
				DateTime today = DateTime.Now;
				// Uses the LastModified property to compare with today's date.
				if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 0)
					Console.WriteLine("\nThe requested URI entity was modified today");
				else
					if (DateTime.Compare(today,myHttpWebResponse.LastModified) == 1)
						Console.WriteLine("\nThe requested URI was last modified on:{0}",
											myHttpWebResponse.LastModified);
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 

    

Return to top


Property: Method (read-only)
Summary
Gets the method used to return the response.
C# Syntax:
public string Method {get;}
Remarks
HttpWebResponse.Method returns the method used to return the response. Common HTTP methods are GET, HEAD, POST, PUT, and DELETE.
Example
The following example checks the string contained in HttpWebResponse.Method, to determine the Http method invoked by the Web server.
        try 
 		  {	
            // Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				string method ;
				method = myHttpWebResponse.Method;
				if (String.Compare(method,"GET") == 0)
					Console.WriteLine("\nThe 'GET' method was successfully invoked on the following Web Server : {0}",
									   myHttpWebResponse.Server);
				// Releases the resources of the response.
				myHttpWebResponse.Close();
          } 
		catch(WebException e) 
		   {
		        Console.WriteLine("\nWebException raised. The following error occured : {0}",e.Status); 
           }
		catch(Exception e)
			{
				Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
			}
	}

    

Return to top


Property: ProtocolVersion (read-only)
Summary
Gets the version of the HTTP protocol used in the response.
C# Syntax:
public Version ProtocolVersion {get;}
Remarks
The HttpWebResponse.ProtocolVersion property contains the HTTP protocol version number of the response sent by the Internet resource.
Example
This example creates an HttpWebRequest and queries for an HttpWebResponse. The example then checks to see if the server is responding with the same version.
            Uri ourUri = new Uri(url);
				// Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(ourUri); 
				myHttpWebRequest.ProtocolVersion = HttpVersion.Version10;
				// Sends the HttpWebRequest and waits for the response.
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				// Ensures that only Http/1.0 responses are accepted. 
				if(myHttpWebResponse.ProtocolVersion != HttpVersion.Version10)
					Console.WriteLine("\nThe server responded with a version other than Http/1.0");
				else
				if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
					Console.WriteLine("\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 ");
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 

    

Return to top


Overridden Property: ResponseUri (read-only)
Summary
Gets the URI of the Internet resource that responded to the request.
C# Syntax:
public override Uri ResponseUri {get;}
Remarks
The HttpWebResponse.ResponseUri property contains the URI of the Internet resource that actually responded to the request. This URI might not be the same as the originally requested URI, if the original server redirected the request.
Example
This example creates an HttpWebRequest and queries for an HttpWebResponse. This example then checks to see if the original URI was redirected by the server.

Return to top


Property: Server (read-only)
Summary
Gets the name of the server that sent the response.
C# Syntax:
public string Server {get;}
Remarks
The HttpWebResponse.Server property contains the value of the Server header returned with the response.
Example
The following example uses the HttpWebResponse.Server property to display the Web server's name to the console.
        try 
 		  {	
            // Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				string method ;
				method = myHttpWebResponse.Method;
				if (String.Compare(method,"GET") == 0)
					Console.WriteLine("\nThe 'GET' method was successfully invoked on the following Web Server : {0}",
									   myHttpWebResponse.Server);
				// Releases the resources of the response.
				myHttpWebResponse.Close();
          } 
		catch(WebException e) 
		   {
		        Console.WriteLine("\nWebException raised. The following error occured : {0}",e.Status); 
           }
		catch(Exception e)
			{
				Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
			}
	}

    

Return to top


Property: StatusCode (read-only)
Summary
Gets the status of the response.
C# Syntax:
public HttpStatusCode StatusCode {get;}
Remarks
The HttpWebResponse.StatusCode parameter is a number indicating the status of the HTTP response. The expected values for status are defined in the HttpStatusCode class.
Example
The following example uses HttpWebResponse.StatusCode to verify that the status of the HttpWebResponse is OK.
    public static void GetPage(String url) 
	{
		try 
 		  {	
				// Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				// Sends the HttpWebRequest and waits for a response.
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
				   Console.WriteLine("\r\nResponse Status Code is OK and StatusDescription is: {0}",
										myHttpWebResponse.StatusDescription);
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 
			
        	} 
		catch(WebException e) 
		   {
		        Console.WriteLine("\r\nWebException Raised. The following error occured : {0}",e.Status); 
           }
		catch(Exception e)
		{
			Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
		}
	}

    

Return to top


Property: StatusDescription (read-only)
Summary
Gets the status description returned with the response.
C# Syntax:
public string StatusDescription {get;}
Remarks
A common status message is OK.
Example
The following example uses HttpWebResponse.StatusDescription to verify that the status of the HttpWebResponse is OK.
    public static void GetPage(String url) 
	{
		try 
 		  {	
				// Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				// Sends the HttpWebRequest and waits for a response.
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
				   Console.WriteLine("\r\nResponse Status Code is OK and StatusDescription is: {0}",
										myHttpWebResponse.StatusDescription);
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 
			
        	} 
		catch(WebException e) 
		   {
		        Console.WriteLine("\r\nWebException Raised. The following error occured : {0}",e.Status); 
           }
		catch(Exception e)
		{
			Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
		}
	}

    

Return to top


Overridden Method: Close()
Summary
Closes the response stream.
C# Syntax:
public override void Close();
Remarks
The HttpWebResponse.Close method closes the response stream and releases the connection to the Internet resource for reuse by other requests.

Note You must call either the Stream.Close or the HttpWebResponse.Close method to close the stream and release the connection for reuse. It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error. Failure to close the stream will cause your application to run out of connections.
Example
The following example demonstrates how to close HttpWebResponse.
            // Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				// Sends the HttpWebRequest and waits for a response.
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				Console.WriteLine("\nResponse Received.Trying to Close the response stream..");
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 
				Console.WriteLine("\nResponse Stream successfully closed");

    

Return to top


Method: CreateObjRef(
   Type requestedType
)
Inherited
See base class member description: System.MarshalByRefObject.CreateObjRef

Summary
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
C# Syntax:
public virtual ObjRef CreateObjRef(
   Type requestedType
);
Parameters:

requestedType

The Type of the object that the new ObjRef will reference.

Return Value:
Information required to generate a proxy.
Exceptions
Exception Type Condition
RemotingException This instance is not a valid remoting object.

Return to top


Method: Dispose(
   bool disposing
)
Summary
C# Syntax:
protected virtual void Dispose(
   bool disposing
);
Parameters:

disposing

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~HttpWebResponse();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: GetHashCode()
Summary
C# Syntax:
public override int GetHashCode();

Return to top


Method: GetLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.GetLifetimeService

Summary
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
C# Syntax:
public object GetLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance.
Remarks
For more information about lifetime services, see the LifetimeServices class.

Return to top


Method: GetResponseHeader(
   string headerName
)
Summary
Gets a specified header contents that was returned with the response.
C# Syntax:
public string GetResponseHeader(
   string headerName
);
Parameters:

headerName

The header value to return.

Return Value:
The contents of the specified header.
Remarks
Use HttpWebResponse.GetResponseHeader to retrieve the contents of particular headers. You must specify which header you wish to return.
Example
This example creates a Web request and queries for a response. If the site requires authentication this example will respond with a challenge string. This string is extracted using HttpWebResponse.GetResponseHeader.
   public static void GetPage(String url) 
	{
	try 
 			{	
				Uri ourUri = new Uri(url);
				// Creates an HttpWebRequest for the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(ourUri); 
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
				Console.WriteLine("\nThe server did not issue any challenge.  Please try again with a protected resource URL.");
				// Releases the resources of the response.
				myHttpWebResponse.Close(); 
			} 
		catch(WebException e) 
		   {
			    HttpWebResponse response = (HttpWebResponse)e.Response;
				if (response != null)
				{
					if (response.StatusCode == HttpStatusCode.Unauthorized)
					{
						string challenge = null;
						challenge= response.GetResponseHeader("WWW-Authenticate");
						if (challenge != null)
							Console.WriteLine("\nThe following challenge was raised by the server:{0}",challenge);
					}
					else
						Console.WriteLine("\nThe following WebException was raised : {0}",e.Message);
				}
				else
					Console.WriteLine("\nResponse Received from server was null");

			}
		catch(Exception e)
		{
			Console.WriteLine("\nThe following Exception was raised : {0}",e.Message);
		}
	}
}

    

Return to top


Overridden Method: GetResponseStream()
Summary
Gets the stream used to read the body of the response from the server.
C# Syntax:
public override Stream GetResponseStream();
Return Value:
A Stream containing the body of the response.
Exceptions
Exception Type Condition
ProtocolViolationException There is no response stream.
Remarks
The HttpWebResponse.GetResponseStream method returns the data stream from the requested Internet resource.

Note You must call either the Stream.Close or HttpWebResponse.Close method to close the stream and release the connection for reuse. It is not necessary to call both Stream.Close and HttpWebResponse.Close, but doing so does not cause an error. Failure to close the stream will cause your application to run out of connections.
Example
The following example demonstrates how to use HttpWebResponse.GetResponseStream to return the Stream instance used to read the response from the server.
            // Creates an HttpWebRequest with the specified URL. 
				HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
				// Sends the HttpWebRequest and waits for the response.			
				HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
				// Gets the stream associated with the response.
				Stream receiveStream = myHttpWebResponse.GetResponseStream();
				Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
				// Pipes the stream to a higher level stream reader with the required encoding format. 
				StreamReader readStream = new StreamReader( receiveStream, encode );
            Console.WriteLine("\r\nResponse stream received.");
				Char[] read = new Char[256];
        		// Reads 256 characters at a time.    
				int count = readStream.Read( read, 0, 256 );
				Console.WriteLine("HTML...\r\n");
				while (count > 0) 
					{
    					// Dumps the 256 characters on a string and displays the string to the console.
						String str = new String(read, 0, count);
						Console.Write(str);
						count = readStream.Read(read, 0, 256);
					}
				Console.WriteLine("");
				// Releases the resources of the response.
				myHttpWebResponse.Close();
				// Releases the resources of the Stream.
				readStream.Close();

    

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: InitializeLifetimeService()
Inherited
See base class member description: System.MarshalByRefObject.InitializeLifetimeService

Summary
Obtains a lifetime service object to control the lifetime policy for this instance.
C# Syntax:
public virtual object InitializeLifetimeService();
Return Value:
An object of type ILease used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the LifetimeServices.LeaseManagerPollTime property.
Remarks
For more information about lifetime services, see the LifetimeServices class.
Example
The following code example demonstrates creating a lease.
 public class MyClass : MarshalByRefObject
 {
   public override Object InitializeLifetimeService()
   {
     ILease lease = (ILease)base.InitializeLifetimeService();
     if (lease.CurrentState == LeaseState.Initial)
     {
          lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
          lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
           lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
     }
       return lease;
   }
 }

    

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.