Wednesday, March 16, 2011

What is the best way to send HTTP requests from Windows Powershell?

What is the best way to send HTTP requests from Windows Powershell?

From stackoverflow
  • Found one way:

    $page = (New-Object System.Net.WebClient).DownloadString("http://localhost/")
    

    Thanks to Steven Murawski for his comment:

    The best way really depends on what task you are trying to accomplish as the two answers below have noted. WebClient is the simplest, but HttpWebRequest is the most flexible.

  • System.Net.WebClient is the easiest way to do it for simple GET request. However if you need to do a POST request for a form then you will need to use System.Net.HttpWebRequest.

  • Hop on sapienpress.com/powershell.asp; go to the bottom of the page and download the book samples. There are a few examples of how to retrieve info via HTTP, as well as how to create a simple WebRequest (say to check a Web server status)

0 comments:

Post a Comment