从Windows Powershell发送HTTP请求的最佳方法是什么?

Tho*_*att 26 powershell networking http

从Windows Powershell发送HTTP请求的最佳方法是什么?

Tho*_*att 33

找到一种方法:

$page = (New-Object System.Net.WebClient).DownloadString("http://localhost/")
Run Code Online (Sandbox Code Playgroud)

感谢Steven Murawski的评论:

最好的方法实际上取决于你要完成的任务,正如下面的两个答案所指出的那样. WebClient是最简单的,但 HttpWebRequest是最灵活的.


Kam*_*rey 10

在PowerShell 3.0+中,您可以使用Invoke-WebRequest

$page = Invoke-WebRequest "http://localhost/"
Run Code Online (Sandbox Code Playgroud)