2016-08-24 91 views
-1

PS script验证Web服务和它的作品:PowerShell的web服务查询

$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?

+0

你甚至读过你提到过的页面吗?看一下'HTTP GET'部分,你应该能够将你需要的东西拼凑在一起,以便在你的请求中指定一个邮政编码。 – TheMadTechnician

+0

这页上的HTTP GET部分在哪里? – Alexan

+0

@alex在http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP –

回答

1

发送请求

$ SITEURL =“HTTP时加入$压缩参数来获取拉链作为输入

参数($ ZIP)

更新您的网址,包括拉链:// WSF .cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP = $ zip

+0

为什么我需要参数($ zip)?我可以在查询字符串中使用$ zip。如果我将这段代码包装到函数中,我需要参数,对吧? – Alexan

+0

是的,如果你想将zip作为param传递给这个脚本或者将它用作函数。否则,你可以硬编码它当然是 –

+0

为什么?op = GetCityWeatherByZIP替换/ GetCityWeatherByZIP?它看起来像?op不适用于param。 – Alexan