HttpWebResponse.ResponseUri 属性

定义

获取响应请求的 Internet 资源的 URI。

public:
 virtual property Uri ^ ResponseUri { Uri ^ get(); };
public override Uri ResponseUri { get; }
member this.ResponseUri : Uri
Public Overrides ReadOnly Property ResponseUri As Uri

属性值

Uri

响应请求的 Internet 资源的 URI。

例外

已释放当前实例。

示例

此示例创建 HttpWebRequest 并查询 , HttpWebResponse 然后检查服务器是否重定向了原始 URI。

Uri^ myUri = gcnew 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.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();
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()

注解

属性 ResponseUri 包含实际响应请求的 Internet 资源的 URI。 如果原始服务器重定向了请求,则此 URI 可能与最初请求的 URI 不同。

属性 ResponseUri 将使用 Content-Location 标头(如果存在)。

需要访问上次重定向 ResponseUri 的应用程序应使用 HttpWebRequest.Address 属性而不是 ResponseUri,因为使用 ResponseUri 属性可能会打开安全漏洞。

适用于