HttpWebResponse.ResponseUri Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan URI sumber daya Internet yang merespons permintaan.
public:
virtual property Uri ^ ResponseUri { Uri ^ get(); };
public override Uri ResponseUri { get; }
member this.ResponseUri : Uri
Public Overrides ReadOnly Property ResponseUri As Uri
Nilai Properti
URI sumber daya Internet yang menanggapi permintaan.
Pengecualian
Instans saat ini telah dibuang.
Contoh
Contoh ini membuat HttpWebRequest kueri dan untuk lalu HttpWebResponse memeriksa untuk melihat apakah URI asli dialihkan oleh server.
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()
Keterangan
Properti ResponseUri berisi URI sumber daya Internet yang benar-benar menanggapi permintaan. URI ini mungkin tidak sama dengan URI yang awalnya diminta, jika server asli mengalihkan permintaan.
Properti ResponseUri akan menggunakan header Content-Location jika ada.
Aplikasi yang perlu mengakses yang terakhir dialihkan ResponseUri harus menggunakan HttpWebRequest.Address properti daripada ResponseUri, karena penggunaan ResponseUri properti dapat membuka kerentanan keamanan.