Compartir a través de


HttpWebResponse.ResponseUri Propiedad

Definición

Obtiene el URI del recurso de Internet que respondió a la solicitud.

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

Valor de propiedad

Uri

El URI del recurso de Internet que respondió a la solicitud.

Excepciones

Se ha eliminado la instancia actual.

Ejemplos

En este ejemplo se crea un HttpWebRequest objeto y se consulta para y HttpWebResponse , a continuación, se comprueba si el servidor redirigió el URI original.

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()

Comentarios

La ResponseUri propiedad contiene el URI del recurso de Internet que realmente respondió a la solicitud. Es posible que este URI no sea el mismo que el URI solicitado originalmente, si el servidor original redirigió la solicitud.

La ResponseUri propiedad usará el encabezado Content-Location si está presente.

Las aplicaciones que necesitan acceder al último redireccionado ResponseUri deben usar la HttpWebRequest.Address propiedad en lugar ResponseUride , ya que el uso de la propiedad puede abrir vulnerabilidades de ResponseUri seguridad.

Se aplica a