WebRequest.RequestUri Property
Assembly: System (in system.dll)
When overridden in a descendant class, the RequestUri property contains the Uri instance that Create method uses to create the request.
Note |
|---|
| The WebRequest class is an abstract class. The actual behavior of WebRequest instances at run time is determined by the descendant class returned by the System.Net.WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest. |
The following example checks the RequestUri property to determine the site originally requested.
// Create a new WebRequest Object to the mentioned URL. WebRequest myWebRequest=WebRequest.Create("http://www.example.com"); Console.WriteLine("\nThe Uri that responded for the Request is {0}",myWebRequest.RequestUri); // Assign the response object of 'WebRequest' to a 'WebResponse' variable. WebResponse myWebResponse=myWebRequest.GetResponse(); // Print the HTML contents of the page to the console. Stream streamResponse=myWebResponse.GetResponseStream(); StreamReader streamRead = new StreamReader( streamResponse ); Char[] readBuff = new Char[256]; int count = streamRead.Read( readBuff, 0, 256 ); Console.WriteLine("\nThe Uri that responded for the Request is '{0}'",myWebRequest.RequestUri);
// Create a new WebRequest Object to the mentioned URL.
WebRequest myWebRequest = WebRequest.Create("http://www.example.com");
Console.WriteLine("\nThe Uri that responded for the Request is {0}",
myWebRequest.get_RequestUri());
// Assign the response object of 'WebRequest' to a 'WebResponse'
// variable.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Print the HTML contents of the page to the console.
Stream streamResponse = myWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
char readBuff[] = new char[256];
int count = streamRead.Read(readBuff, 0, 256);
Console.WriteLine("\nThe Uri that responded for the Request"
+ " is '{0}'", myWebRequest.get_RequestUri());
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note