用于内容的Invoke-RestMethod的消息体类型application / xml

时间:2018-02-09 19:58:39

标签: rest powershell

我想将XML文档作为REST方法调用的一部分传递:

$url = 'https:foobar/get/jars/2/cookies/chocolate-chip'
[xml]$message = @'
<Cookie>
<Password auto="false">Eat</Password>
</Cookie>
'@
$method = 'Put'
$credential = Get-Credential $env:username

$return_message = Invoke-RestMethod -Uri $url -Body $message -Method $method -ContentType 'application/xml'

它爆炸了以下:

&#34; Invoke-RestMethod:基础连接已关闭:发送时发生意外错误。&#34;

&amp; $ @ *如何在请求正文中传递XML文档。我尝试过传递带有XML标记的字符串。

1 个答案:

答案 0 :(得分:-1)

你们没有人帮忙。

我的网址错了(至少在我的例子中)。以下代码将起作用:

$me = Get-Credential $env:username

Invoke-RestMethod -Credential $me `
-Method Put `
-Uri 'https://deezNutz.myCompany.com/pfft/users/billy `
-Body [xml]'<User><Enable>False</Enable></User>' `
-ContentType 'application/xml'
相关问题