0

我有一个需要使用 cmd 或 Powershell 调用的 Web 服务(以便可以保存和安排脚本),它位于特定的 URI。只需向该 URI 发送 GET 请求即可触发必要的任务。

使用 cmd 或 PowerShell 触发此 Web 服务的最简单方法是什么?(理想情况下是单线)

4

3 回答 3

2

在 PowerShell 中尝试System.Net.Webclient对象:

$client = New-Object System.Net.WebClient
$client.DownloadStringAsync("http://www.example.com/") | Out-Null

您也可以在 VBScript 中使用XMLHTTPRequest执行此操作:

Set req = CreateObject("Msxml2.XMLHttp.6.0")
req.open "GET", "http://www.example.com/", True
req.send
于 2013-05-20T16:24:56.687 回答
1

在 powershell / 作为 powershell 脚本中尝试以下操作:

[System.Net.WebRequest]::CreateHttp("http://www.stackoverflow.com").GetResponse() | Out-Null

我不是 webrequest 方面的专家,但如果需要(或智能)为此类请求禁用 keep-alive,请使用以下命令:

$req = [System.Net.WebRequest]::CreateHttp("http://www.stackoverflow.com")
$req.KeepAlive = $false
$req.GetResponse() | Out-Null

Out-Null如果需要,请删除并存储响应。

于 2013-05-20T16:24:51.670 回答
0

如果您曾经更新到 PowerShell v3,则可以使用Invoke-WebRequest命令。

Invoke-WebRequest http://www.stackoverflow.com
于 2013-05-20T18:46:56.197 回答