首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell: Invoke-WebRequest

Powershell: Invoke-WebRequest
EN

Stack Overflow用户
提问于 2017-04-03 15:31:41
回答 1查看 5.1K关注 0票数 1

我使用下面的powershell脚本将存储在文本文件(soap.txt)中的xml数据发送到端点。

代码语言:javascript
复制
$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,这样我就可以丰富内容,但是我面临一些问题,下面是代码。

代码语言:javascript
复制
## 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'

我收到以下错误

我也试过

代码语言:javascript
复制
$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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-03 16:00:32

答案是删除变量中的XML缩进,这个问题在某个地方有文档吗?或者这是一个限制。

代码语言:javascript
复制
$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>
"@
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43188652

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档