簡體   English   中英

使用Powershell腳本調用WebRequest

[英]Invoke a WebRequest using Powershell Script

腳本新手。 當我嘗試使用輸入是xml的方式訪問Web服務時,遇到了一些錯誤。

當我嘗試調用WebRequest時,得到了xml的內容。

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

其中,$ uri是具有服務url的變量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

請在這件事上給予我幫助

好吧, Invoke-WebRequest cmdlet中沒有-CalculateTax參數。 而且,這就是您看到的錯誤。

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>]

如果您要調用特定方法,請使用New-WebServiceProxy ,而不是使用Invoke-WebRequest 這是文檔中的一個示例:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM