Export (0) Print
Expand All

HttpWebRequest.ProtocolVersion Property

Gets or sets the version of HTTP to use for the request.

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

Property Value

The HTTP version to use for the request. The default is HttpVersion.Version11.

Exceptions

Exception Type Condition
ArgumentException The HTTP version is set to a value other than 1.0 or 1.1.

Remarks

The HttpWebRequest class supports only versions 1.0 and 1.1 of HTTP. Setting ProtocolVersion to a different version throws an exception.

Note   To set the HTTP version of the current request, use the Version10 and Version11 fields of the HttpVersion class.

Example

[Visual Basic, C#, C++] The following example sets the ProtocolVersion Property.

[Visual Basic] 
' Create a new 'HttpWebRequest' Object to the mentioned URL.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)
' Use the existing 'ProtocolVersion' , and display it onto the console.    
Console.WriteLine(ControlChars.Cr + "The 'ProtocolVersion' of the protocol used is {0}", myHttpWebRequest.ProtocolVersion)
' Set the 'ProtocolVersion' property of the 'HttpWebRequest' to 'Version1.0' .
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10
'  Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine(ControlChars.Cr + "The 'ProtocolVersion' of the protocol changed to {0}", myHttpWebRequest.ProtocolVersion)
Console.WriteLine(ControlChars.Cr + "The protocol version of the response object is {0}", myHttpWebResponse.ProtocolVersion)

[C#] 
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
// Use the existing 'ProtocolVersion' , and display it onto the console.    
Console.WriteLine("\nThe 'ProtocolVersion' of the protocol used is {0}",myHttpWebRequest.ProtocolVersion);
// Set the 'ProtocolVersion' property of the 'HttpWebRequest' to 'Version1.0' .
myHttpWebRequest.ProtocolVersion=HttpVersion.Version10;
 // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
 HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
Console.WriteLine("\nThe 'ProtocolVersion' of the protocol changed to {0}",myHttpWebRequest.ProtocolVersion);
Console.WriteLine("\nThe protocol version of the response object is {0}",myHttpWebResponse.ProtocolVersion);

[C++] 
// Create a new 'HttpWebRequest' Object to the mentioned URL.
HttpWebRequest* myHttpWebRequest =
   dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"http://www.microsoft.com"));
// Use the existing 'ProtocolVersion' , and display it onto the console.
Console::WriteLine(S"\nThe 'ProtocolVersion' of the protocol used is {0}",
   myHttpWebRequest->ProtocolVersion);
// Set the 'ProtocolVersion' property of the 'HttpWebRequest' to 'Version1::0' .
myHttpWebRequest->ProtocolVersion = HttpVersion::Version10;

// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse* myHttpWebResponse =
   dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());
Console::WriteLine(S"\nThe 'ProtocolVersion' of the protocol changed to {0}", 
   myHttpWebRequest->ProtocolVersion);
Console::WriteLine(S"\nThe protocol version of the response Object* is {0}",
   myHttpWebResponse->ProtocolVersion);

[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

HttpWebRequest Class | HttpWebRequest Members | System.Net Namespace

Show:
© 2014 Microsoft