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

前端 未结 3 732
旧时难觅i
旧时难觅i 2020-12-14 07:29

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

相关标签:
3条回答
  • 2020-12-14 07:53

    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.

    0 讨论(0)
  • 2020-12-14 08:01

    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.

    0 讨论(0)
  • 2020-12-14 08:03

    In PowerShell 3.0+ you can use Invoke-WebRequest

    $page = Invoke-WebRequest "http://localhost/"
    
    0 讨论(0)
提交回复
热议问题