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

application/xml内容类型的Invoke RestMethod的消息体,rest,powershell,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 $retu

我想将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'
$url='https:foobar/get/jars/2/cookies/chocolate chip'
[xml]$message=@'
吃
'@
$method='Put'
$credential=获取凭据$env:username
$return_message=Invoke RestMethod-Uri$url-Body$message-Method$Method-ContentType'application/xml'
爆炸的原因如下:

“Invoke RestMethod:基础连接已关闭:发送时发生意外错误。”


&$@*如何在请求体中传递XML文档。我试着传递一个带有XML标记的字符串。

你们这些人帮不了什么忙

我的URL是错误的(至少在我的例子中是这样)。以下代码将起作用:

$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'
$me=获取凭证$env:username
调用RestMethod-凭证$me`
-方法Put`
-Uri'https://deezNutz.myCompany.com/pfft/users/billy `
-Body[xml]“False”`
-ContentType“应用程序/xml”