What is the best way to send HTTP requests from Windows Powershell?
Asked
Active
Viewed 2.1k times
26
-
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. – Steven Murawski Dec 04 '08 at 14:20
3 Answers
33
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.

Thomas Bratt
- 48,038
- 36
- 121
- 139
-
If you need to control anything related to timeouts then you must use httpwebrequest or webrequest. – David Newcomb May 16 '12 at 11:07
12
In PowerShell 3.0+ you can use Invoke-WebRequest
$page = Invoke-WebRequest "http://localhost/"

Kamarey
- 10,832
- 7
- 57
- 70
2
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.

Turnkey
- 9,266
- 3
- 27
- 36