使用Powershell脚本调用WebRequest

时间:2014-01-16 08:33:47

标签: powershell

是脚本新手。当我尝试使用输入为xml的网络服务时,我遇到了一些错误。

获取xml的内容以及何时尝试调用WebRequest。

[xml]$sun= Invoke-WebRequest -Uri $uri -CalculateTax post -ContentType "String" -InFile $Input.OuterXml.

其中,$ uri是具有服务url的变量 CalculateTax是服务的方法 $ Input是具有XML内容的Variable 获取错误

Invoke-WebRequest : A parameter cannot be found that matches parameter name 'CalculateTax'.   
+    [xml]$sun= Invoke-WebRequest -Uri $uri -CalculateTax Post -ContentType "string"  ...
+                                        ~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

请帮我解决这个问题

1 个答案:

答案 0 :(得分:3)

嗯,-CalculateTax cmdlet中没有Invoke-WebRequest参数。而且,这就是你看到的错误。

PS C:\> Get-Command Invoke-WebRequest -Syntax

Invoke-WebRequest [-Uri] <uri> [-UseBasicParsing] [-WebSession <WebRequestSession>] [-SessionVariable <string>]
[-Credential <pscredential>] [-UseDefaultCredentials] [-CertificateThumbprint <string>] [-Certificate
<X509Certificate>] [-UserAgent <string>] [-DisableKeepAlive] [-TimeoutSec <int>] [-Headers <IDictionary>]
[-MaximumRedirection <int>] [-Method <WebRequestMethod>] [-Proxy <uri>] [-ProxyCredential <pscredential>]
[-ProxyUseDefaultCredentials] [-Body <Object>] [-ContentType <string>] [-TransferEncoding <string>] [-InFile <string>]
[-OutFile <string>] [-PassThru] [<CommonParameters>]

如果您正在考虑调用特定方法,请不要使用Invoke-WebRequest,请查看New-WebServiceProxy。以下是文档中的示例:

PS C:\>$URI = "http://www.webservicex.net/uszip.asmx?WSDL"
PS C:\>$zip = New-WebServiceProxy -Uri $URI -Namespace WebServiceProxy -Class USZip
PS C:\>$zip | get-member -type method
PS C:\>$zip.getinfobyzip(20500).table