0
我正在使用以下PowerShell腳本將存儲在文本文件(soap.txt)中的xml數據發送到端點。Powershell:Invoke-WebRequest
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("charset", 'utf-8')
$headers.Add("SOAPAction", 'nms:rtEvent#PushEvent')
Invoke-WebRequest http://localhost:8080/nl/jsp/soaprouter.jsp -Method Post -ContentType 'text/xml' -Headers $headers -InFile D:\Scripts\archive\soap.txt
雖然上述方法工作得很好,我想使用 - 身體PARAM代替,這樣我可以充實內容,但我遇到了一些問題,下面是代碼。
## Set SOAP headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("charset", 'utf-8')
$headers.Add("SOAPAction", 'nms:rtEvent#PushEvent')
$url = "http://localhost:8080/nl/jsp/soaprouter.jsp"
$body = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:nms:rtEvent">
<soapenv:Header/>
<soapenv:Body>
...etc etc
</soapenv:Body>
</soapenv:Envelope>'
Invoke-WebRequest -Method Post -Uri $url -Headers $headers -Body $body -ContentType 'application/xml'
我收到以下錯誤
我也試過
$body = @"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:nms:rtEvent">
<soapenv:Header/>
<soapenv:Body>
...rest of code here asd
</soapenv:Body>
</soapenv:Envelope>
"@
Invoke-WebRequest -Method Post -Uri $url -ContentType 'text/xml' -Headers $headers -Body $body
,我得到的頭必須用此時,相應的屬性或方法進行修改,所以我追加內容類型也標題,但也不起作用,我使用的PowerShell 3.0
請問您能分享一下您在infile中傳遞的內容嗎? –
@RanadipDutta本質上,在$ body變量中定義的內容相同,我剛剛刪除了機密細節,簡單的xml SOAP –
好。讓我通過它,然後創建一個樣本。 –