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 Uri RequestUri { get; }
/** @property */
public Uri get_RequestUri ()

public function get RequestUri () : Uri

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 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.

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 = 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.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft