Export (0) Print
Expand All

HttpWebResponse.ProtocolVersion Property

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

[Visual Basic]
Public ReadOnly Property ProtocolVersion As Version
[C#]
public Version ProtocolVersion {get;}
[C++]
public: __property Version* get_ProtocolVersion();
[JScript]
public function get ProtocolVersion() : Version;

Property Value

A Version containing the HTTP protocol version of the response.

Exceptions

Exception Type Condition
ObjectDisposedException The current instance has been disposed.

Remarks

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

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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()

[C#] 
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(); 

[C++] 
Uri* ourUri = new Uri(url);
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(ourUri));
myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
// Ensures that only Http/1.0 responses are accepted.
if (myHttpWebResponse->ProtocolVersion != HttpVersion::Version10)
   Console::WriteLine(S"\nThe server responded with a version other than Http/1.0");
else
   if (myHttpWebResponse->StatusCode == HttpStatusCode::OK)
      Console::WriteLine(S"\nRequest sent using version Http/1.0. Successfully received response with version HTTP/1.0 ");
// Releases the resources of the response.
myHttpWebResponse->Close();

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace

Show:
© 2014 Microsoft