WebResponse.ResponseUri 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在衍生類別中覆寫時,取得對要求實際回應的網際網路資源 URI。
public:
abstract property Uri ^ ResponseUri { Uri ^ get(); };
public:
virtual property Uri ^ ResponseUri { Uri ^ get(); };
public abstract Uri ResponseUri { get; }
public virtual Uri ResponseUri { get; }
member this.ResponseUri : Uri
Public MustOverride ReadOnly Property ResponseUri As Uri
Public Overridable ReadOnly Property ResponseUri As Uri
屬性值
Uri 類別的執行個體,它包含對要求實際回應的網際網路資源 URI。
例外狀況
當屬性在子代類別中未覆寫時,會嘗試取得或設定該屬性。
範例
下列範例會 ResponseUri 使用 屬性來判斷來源的位置 WebResponse 。
Uri^ ourUri = gcnew Uri( url );
// Create a 'WebRequest' object with the specified url.
WebRequest^ myWebRequest = WebRequest::Create( url );
// Send the 'WebRequest' and wait for response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();
// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if ( ourUri->Equals( myWebResponse->ResponseUri ) )
{
Console::WriteLine( "\nRequest Url : {0} was not redirected", url );
}
else
{
Console::WriteLine( "\nRequest Url : {0} was redirected to {1}", url, myWebResponse->ResponseUri );
}
// Release resources of response object.
myWebResponse->Close();
Uri ourUri = new Uri(url);
// Create a 'WebRequest' object with the specified url.
WebRequest myWebRequest = WebRequest.Create(url);
// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Use "ResponseUri" property to get the actual Uri from where the response was attained.
if (ourUri.Equals(myWebResponse.ResponseUri))
Console.WriteLine("\nRequest Url : {0} was not redirected",url);
else
Console.WriteLine("\nRequest Url : {0} was redirected to {1}",url,myWebResponse.ResponseUri);
// Release resources of response object.
myWebResponse.Close();
Dim ourUri As New Uri(url)
' Create a 'WebRequest' object with the specified url.
Dim myWebRequest As WebRequest = WebRequest.Create(url)
' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
' "ResponseUri" property is used to get the actual Uri from where the response was attained.
If ourUri.Equals(myWebResponse.ResponseUri) Then
Console.WriteLine(ControlChars.Cr + "Request Url : {0} was not redirected", url)
Else
Console.WriteLine(ControlChars.Cr + "Request Url : {0} was redirected to {1}", url, myWebResponse.ResponseUri)
End If
' Release resources of response object.
myWebResponse.Close()
備註
ResponseUri屬性包含實際提供響應數據的因特網資源 URI。 如果基礎通訊協議允許重新導向要求,此資源可能不是原始要求的 URI。
注意
類別 WebResponse 是類別 abstract
。 運行時間實例的實際行為是由 所WebRequest.GetResponse傳回的WebResponse子系類別所決定。 如需預設值和例外狀況的詳細資訊,請參閱 子系類別的檔,例如 HttpWebResponse 和 FileWebResponse。