Saturday 14 March 2009

Get-HTTPVersion.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates use of the HTTPVersion class   
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample,using PowerShell 
  6. .NOTES 
  7.     File Name  : Get-HTTPVersion.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell V2 CTP3 
  10. .LINK 
  11.     Sample posted to: 
  12.     http://pshscripts.blogspot.com/2009/03/get-httpversionps1.html 
  13.     Original MSDN sample at: 
  14.     http://msdn.microsoft.com/en-us/library/system.net.httpversion.aspx 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-HTTPVersion.ps1' 
  17.     The 'ProtocolVersion' of the protocol before assignment is :1.1 
  18.     The 'ProtocolVersion' of the protocol after  assignment is :1.0 
  19.     The 'ProtocolVersion' of the response object is :1.1 
  20. #> 
  21.  
  22. ### 
  23. # Start of Script 
  24. ### 
  25.   
  26. # Create a 'HttpWebRequest' object and display  
  27. $myHttpWebRequest=[system.net.webrequest]::Create("http://www.microsoft.com") 
  28. "The 'ProtocolVersion' of the protocol before assignment is :{0}" -f $myHttpWebRequest.ProtocolVersion 
  29.  
  30. # Assign Version10 to ProtocolVersion 
  31. $myHttpWebRequest.ProtocolVersion=[system.net.HttpVersion]::Version10 
  32.  
  33. #  Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable 
  34. $myHttpWebResponse=$myHttpWebRequest.GetResponse(); 
  35.  
  36. "The 'ProtocolVersion' of the protocol after  assignment is :{0}" -f $myHttpWebRequest.ProtocolVersion 
  37. "The 'ProtocolVersion' of the response object is :{0}" -f $myHttpWebResponse.ProtocolVersion 
  38.  
  39. # End of script 

No comments: