Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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 */
public Uri get_ResponseUri ()

public override function get ResponseUri () : Uri

Not applicable.

Property Value

A Uri that contains the URI of the Internet resource that responded to the request.
Exception typeCondition

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.

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 = (HttpWebRequest)
    WebRequest.Create(myUri);

// Send the request and wait for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
    myHttpWebRequest.GetResponse();

if (myHttpWebResponse.get_StatusCode().Equals(HttpStatusCode.OK)) {
    Console.WriteLine("\nRequest succeeded and the requested "
        + "information is in the response ,Description : {0}", 
        myHttpWebResponse.get_StatusDescription());
}

if (myUri.Equals(myHttpWebResponse.get_ResponseUri())) {
    Console.WriteLine("\nThe Request Uri was not redirected "
        + "by the server");
}
else {
    Console.WriteLine("\nThe Request Uri was redirected to :{0}", 
        myHttpWebResponse.get_ResponseUri());
} // Release resources of response object.

myHttpWebResponse.Close();

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.