Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HttpWebResponse.ProtocolVersion Property

Gets the version of the HTTP protocol that is used in the response.

Namespace: System.Net
Assembly: System (in system.dll)

public Version ProtocolVersion { get; }
/** @property */
public Version get_ProtocolVersion ()

public function get ProtocolVersion () : Version

Not applicable.

Property Value

A Version that contains the HTTP protocol version of the response.
Exception typeCondition

ObjectDisposedException

The current instance has been disposed.

The ProtocolVersion property contains the HTTP protocol version number of the response sent by the Internet resource.

This example creates an HttpWebRequest and queries for an HttpWebResponse. The example then checks to see if the server is responding with the same version.

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

Uri ourUri = new Uri(url);

// Creates an HttpWebRequest for the specified URL. 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
    WebRequest.Create(ourUri);
myHttpWebRequest.set_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.get_ProtocolVersion().
    Equals(HttpVersion.Version10)) {
    Console.WriteLine("\nThe server responded with a version "
        + "other than Http/1.0");
}
else {
    if (myHttpWebResponse.get_StatusCode().
        Equals(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();

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.