2008/10/28

PowerShell : 如何使用PowerShell呼叫WebRequest?

節錄出程式內的function應該就能了解了:


function GoRefresh($gdString)
{
$today = Get-Date
write-host "更新:" $id "-->" $today

$url = "http://192.168.1.100/refresh_html.ashx?id=" + $id
write-host "url:" $url

$request = [System.Net.WebRequest]::Create($url)

$response = $request.GetResponse()
$requestStream = $response.GetResponseStream()
$readStream = new-object System.IO.StreamReader $requestStream
new-variable tmp
$tmp = $readStream.ReadToEnd()
write-host "response:" $tmp
$readStream.Close()
$response.Close()
}

參考來源:Basic Powershell examples, couple useful commands

沒有留言: