我使用下面的powershell脚本将存储在文本文件(soap.txt)中的xml数据发送到端点。
$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虽然上面的方法很好,但我希望使用-Body 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而且我知道必须使用appropiate属性或方法修改标头,所以我也将内容类型附加到标头中,但这也不起作用,我使用的是powershell 3.0

发布于 2017-04-03 16:00:32
答案是删除变量中的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>
"@https://stackoverflow.com/questions/43188652
复制相似问题