What is the best way to send HTTP requests from Windows Powershell?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
In PowerShell 3.0+ you can use Invoke-WebRequest
$page = Invoke-WebRequest "http://localhost/"
回答3:
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.