脚本新手。当我尝试以输入为xml的形式访问Web服务时遇到一些错误。
当我尝试调用WebRequest时,得到了xml的内容。
[xml]$sun= Invoke-WebRequest -Uri $uri -CalculateTax post -ContentType "String" -InFile $Input.OuterXml.
其中,$ uri是具有服务网址的变量
CalculateTax是服务的方法
$ Input是具有XML内容的变量
得到错误为
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
请在这件事上给予我帮助
最佳答案
好吧,在-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
关于powershell - 使用Powershell脚本调用WebRequest,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21156820/