共用方式為


HttpWebResponse.ResponseUri 屬性

定義

取得回應要求之網際網路資源的 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

回應要求的因特網資源 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屬性包含實際回應要求之因特網資源的 URI。 如果原始伺服器重新導向要求,此 URI 可能與原始要求的 URI 不同。

如果存在,屬性 ResponseUri 將會使用 Content-Location 標頭。

需要存取最後一個重新導向 ResponseUri 的應用程式應該使用 HttpWebRequest.Address 屬性,而不是 ResponseUri,因為使用 ResponseUri 屬性可能會開啟安全性弱點。

適用於