Export (0) Print
Expand All

WebRequest.RequestUri Property

When overridden in a descendant class, gets the URI of the Internet resource associated with the request.

Namespace: System.Net
Assembly: System (in system.dll)

public:
virtual property Uri^ RequestUri {
	Uri^ get ();
}
/** @property */
public Uri get_RequestUri ()

public function get RequestUri () : Uri

Not applicable.

Property Value

A Uri representing the resource associated with the request

Exception typeCondition

NotImplementedException

Any attempt is made to get or set the property, when the property is not overridden in a descendant class.

When overridden in a descendant class, the RequestUri property contains the Uri instance that Create method uses to create the request.

NoteNote:

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 WebRequest.Create method. For more information about default values and exceptions, see the documentation for the descendant classes, such as HttpWebRequest and FileWebRequest.

Notes to Inheritors: RequestUri must contain the original Uri instance passed to the Create method. If the protocol is able to redirect the request to a different URI to service the request, the descendant must provide a property to contain the URI that actually services the request

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 = gcnew StreamReader( streamResponse );
array<Char>^ readBuff = gcnew array<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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft