HttpVersion Class
.NET Framework 3.5
Defines the HTTP version numbers that are supported by the HttpWebRequest and HttpWebResponse classes.
Assembly: System (in System.dll)
The HttpVersion class defines the HTTP versions that are supported by the HttpWebRequest and HttpWebResponse classes. The HTTP version number is used to control version-specific features of HTTP, such as pipelining and chunking.
The following example demonstrates the use of HttpVersion.
// Create a 'HttpWebRequest' object. HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com"); Console.WriteLine("\nThe 'ProtocolVersion' of the protocol before assignment is :{0}",myHttpWebRequest.ProtocolVersion); // Assign Version10 to ProtocolVersion. 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 after assignment is :{0}",myHttpWebRequest.ProtocolVersion); Console.WriteLine("\nThe 'ProtocolVersion' of the response object is :{0}",myHttpWebResponse.ProtocolVersion);
// Create a 'HttpWebRequest' object.
HttpWebRequest* myHttpWebRequest =
dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"http://www.microsoft.com"));
Console::WriteLine(S"\nThe 'ProtocolVersion' of the protocol before assignment is : {0}",
myHttpWebRequest->ProtocolVersion);
// Assign Version10 to ProtocolVersion.
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 after assignment is : {0}",
myHttpWebRequest->ProtocolVersion);
Console::WriteLine(S"\nThe 'ProtocolVersion' of the response Object* is : {0}",
myHttpWebResponse->ProtocolVersion);
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
HttpVersion Class using PowerShell
<# .SYNOPSIS Demonstrates use of the HTTPVersion class
.DESCRIPTION
This script is a re-write of an MSDN sample,using PowerShell
.NOTES
File Name : Get-HTTPVersion.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell V2 CTP3
.LINK
Sample posted to:
http://www.pshscripts.blogspot.com O
Original MSDN sample at:
http://msdn.microsoft.com/en-us/library/system.net.httpversion.aspx
.EXAMPLE
PSH [C:\foo]: .\Get-HTTPVersion.ps1'
The 'ProtocolVersion' of the protocol before assignment is :1.1
The 'ProtocolVersion' of the protocol after assignment is :1.0
The 'ProtocolVersion' of the response object is :1.1
#>
###
# Start of Script
###
# Create a 'HttpWebRequest' object and display
$myHttpWebRequest=[system.net.webrequest]::Create("http://www.microsoft.com")
"The 'ProtocolVersion' of the protocol before assignment is :{0}" -f $myHttpWebRequest.ProtocolVersion
# Assign Version10 to ProtocolVersion
$myHttpWebRequest.ProtocolVersion=[system.net.HttpVersion]::Version10
# Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable
$myHttpWebResponse=$myHttpWebRequest.GetResponse();
"The 'ProtocolVersion' of the protocol after assignment is :{0}" -f $myHttpWebRequest.ProtocolVersion
"The 'ProtocolVersion' of the response object is :{0}" -f $myHttpWebResponse.ProtocolVersion
# End of script
- 4/22/2008
- Thomas Lee
- 3/14/2009
- Thomas Lee