使用 powershell 请求 http 请求 [英] http requests with powershell
问题描述
我希望使用 powershell 向网页发出 http 请求,这可能吗?如果可能,我该如何实现?
I am looking to make http requests to web pages with powershell, is this possible and if so, how may I achieve this?
我可以向 https 页面发出请求吗?我能够使用 bat 文件而不是 https 发出 http 请求,希望我可以使用 powershell 发出 https 页面请求.
Can I make requests to https pages? I am able to make http requests with a bat file but not https, was hoping I could https page requests with powershell.
推荐答案
您可以使用 .NET 框架提供的常用 WebRequest
和 HttpWebRequest
类.
You can use the usual WebRequest
and HttpWebRequest
classes provided by the .NET framework.
$request = [System.Net.WebRequest]::Create('http://example.com')
# do something with $request
它与使用 C# 中相同的类和 API 没有什么不同,除了与 PowerShell 的语法差异.
It's no different from using the same classes and APIs from C#, except for the syntactic differences to PowerShell.
PowerShell v3 还带来了 Invoke-WebRequest
和其他一些.
PowerShell v3 also brings Invoke-WebRequest
and a few others.
这篇关于使用 powershell 请求 http 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!