Export (0) Print
Expand All

HttpWebResponse.ResponseUri Property

Gets the URI of the Internet resource that responded to the request.

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

public override Uri ResponseUri { get; }

Property Value

Type: System.Uri
A Uri that contains the URI of the Internet resource that responded to the request.

ExceptionCondition
ObjectDisposedException

The current instance has been disposed.

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

The ResponseUri property will use the Content-Location header if present.

Applications that need to access the last redirected ResponseUri should use the HttpWebRequest.Address property rather than ResponseUri, since the use of ResponseUri property may open security vulnerabilities.

This example creates an HttpWebRequest and queries for an HttpWebResponse and then checks to see whether the original URI was redirected by the server.

			Uri myUri = new Uri(url);
			// Create a 'HttpWebRequest' object for the specified url. 
			HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); 
			// Send the request and wait for response.
			HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
			if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
                Console.WriteLine("\nRequest succeeded and the requested information is in the response ,Description : {0}",
									myHttpWebResponse.StatusDescription);
			if (myUri.Equals(myHttpWebResponse.ResponseUri))
				Console.WriteLine("\nThe Request Uri was not redirected by the server");
			else
				Console.WriteLine("\nThe Request Uri was redirected to :{0}",myHttpWebResponse.ResponseUri);
			// Release resources of response object.
			myHttpWebResponse.Close(); 
Uri* myUri = new Uri(url);
// Create a 'HttpWebRequest' object for the specified url.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(myUri));
// Send the request and wait for response.
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
if (myHttpWebResponse->StatusCode == HttpStatusCode::OK)
   Console::WriteLine(S"\nRequest succeeded and the requested information is in the response , Description : {0}",
   myHttpWebResponse->StatusDescription);
if (myUri->Equals(myHttpWebResponse->ResponseUri))
   Console::WriteLine(S"\nThe Request Uri was not redirected by the server");
else
   Console::WriteLine(S"\nThe Request Uri was redirected to : {0}",
   myHttpWebResponse->ResponseUri);
// Release resources of response Object*.
myHttpWebResponse->Close();

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft