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.

[Visual Basic]
Public Overridable ReadOnly Property RequestUri As Uri
[C#]
public virtual Uri RequestUri {get;}
[C++]
public: __property virtual Uri* get_RequestUri();
[JScript]
public function get RequestUri() : Uri;

Property Value

A Uri representing the resource associated with the request

Exceptions

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

Remarks

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 (MustInherit in Visual Basic) 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

Example

[Visual Basic, C#, C++] The following example checks the RequestUri property to determine the site originally requested.

[Visual Basic] 
' Create a new WebRequest Object to the mentioned URL.
Dim myWebRequest As WebRequest = WebRequest.Create("http://www.example.com")
Console.WriteLine(ControlChars.Cr + "The Uri that responded for the Request is   {0}", myWebRequest.RequestUri)
' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' Print the HTML contents of the page to the console. 
Dim streamResponse As Stream = myWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
Console.WriteLine(ControlChars.Cr + "The Uri that responded for the Request is   {0}", myWebRequest.RequestUri)

[C#] 
// 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);

[C++] 
// Create a new WebRequest object to the mentioned URL.
WebRequest* myWebRequest=WebRequest::Create(S"http://www.google.com");
Console::WriteLine(S"\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(S"\nThe Uri that responded for the Request is ' {0}'",
   myWebRequest->RequestUri);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

WebRequest Class | WebRequest Members | System.Net Namespace | HttpWebRequest.RequestUri | HttpWebRequest.Address

Show:
© 2014 Microsoft