HttpWebResponse.ProtocolVersion Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene la versión del protocolo HTTP usado en la respuesta.
public:
property Version ^ ProtocolVersion { Version ^ get(); };
public Version ProtocolVersion { get; }
member this.ProtocolVersion : Version
Public ReadOnly Property ProtocolVersion As Version
Valor de propiedad
Objeto Version que contiene la versión del usado HTTP de la respuesta.
Excepciones
Se ha eliminado la instancia actual.
Ejemplos
En este ejemplo se crea un HttpWebRequest objeto y se consulta para .HttpWebResponse A continuación, el ejemplo comprueba si el servidor responde con la misma versión.
Uri^ ourUri = gcnew Uri( url );
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( ourUri ) );
myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );
// Ensures that only Http/1.0 responses are accepted.
if ( myHttpWebResponse->ProtocolVersion != HttpVersion::Version10 )
{
Console::WriteLine( "\nThe server responded with a version other than Http/1.0" );
}
else if ( myHttpWebResponse->StatusCode == HttpStatusCode::OK )
{
Console::WriteLine( "\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 " );
}
// Releases the resources of the response.
myHttpWebResponse->Close();
Uri ourUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(ourUri);
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Ensures that only Http/1.0 responses are accepted.
if(myHttpWebResponse.ProtocolVersion != HttpVersion.Version10)
Console.WriteLine("\nThe server responded with a version other than Http/1.0");
else
if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
Console.WriteLine("\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 ");
// Releases the resources of the response.
myHttpWebResponse.Close();
Dim ourUri As New Uri(url)
' Creates an HttpWebRequest with the specified URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(ourUri), HttpWebRequest)
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10
' Sends the request and waits for the response.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
'The ProtocolVersion property is used to ensure that only Http/1.0 responses are accepted.
If myHttpWebResponse.ProtocolVersion Is HttpVersion.Version10 Then
Console.WriteLine(ControlChars.NewLine + "The server responded with a version other than Http/1.0")
Else
If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
Console.WriteLine(ControlChars.NewLine + "Request sent using version HTTP/1.0. Successfully received response with version Http/1.0 ")
End If
End If
' Releases the resources of the response.
myHttpWebResponse.Close()
Comentarios
La ProtocolVersion propiedad contiene el número de versión del protocolo HTTP de la respuesta enviada por el recurso de Internet.