PowerShell 网络服务查询

PowerShell webservice query

PS script 用于验证网络服务并且有效:

$SiteURL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP"

$request = [Net.HttpWebRequest]::Create($SiteURL)    
try 
{     
    #Get the response from the requst 
    $response = [Net.HttpWebResponse]$request.GetResponse() 
    Write-Host "The service is running." 
    $request.Abort() 
}     
Catch  
{ 
    Write-Warning "The service of site does not run or maybe you don't have the Credential" 
}

但是我如何指定查询参数,ZIP?

添加 $zip 参数以获取 zip 作为输入

参数($zip)

更新您的 url 以在发送请求时包含 zip

$siteURL="http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=$zip"