Export (0) Print
Expand All

HttpWebResponse.ResponseUri Property

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

[Visual Basic]
Overrides Public ReadOnly Property ResponseUri As Uri
[C#]
public override Uri ResponseUri {get;}
[C++]
public: __property Uri* get_ResponseUri();
[JScript]
public override function get ResponseUri() : Uri;

Property Value

A Uri containing the URI of the Internet resource that responded to the request.

Exceptions

Exception Type Condition
ObjectDisposedException The current instance has been disposed.

Remarks

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.

Example

[Visual Basic, C#, C++] This example creates an HttpWebRequest and queries for an HttpWebResponse and then checks to see whether the original URI was redirected by the server.

[Visual Basic] 
Dim myUri As New Uri(url)
' Create a 'HttpWebRequest' object for the specified url 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest)
' Send the request and wait for response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
    Console.WriteLine(ControlChars.Cr + "Request succeeded and the requested information is in the response , Description : {0}", myHttpWebResponse.StatusDescription)
End If
If myUri.Equals(myHttpWebResponse.ResponseUri) Then
    Console.WriteLine(ControlChars.Cr + "The Request Uri was not redirected by the server")
Else
    Console.WriteLine(ControlChars.Cr + "The Request Uri was redirected to :{0}", myHttpWebResponse.ResponseUri)
End If
' Release resources of response object.
myHttpWebResponse.Close()

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

[C++] 
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();

[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

HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace

Show:
© 2014 Microsoft