gpt4 book ai didi

适用于 ServiceNow 的 Powershell SOAP

转载 作者:行者123 更新时间:2023-12-03 22:32:37 27 4
gpt4 key购买 nike

我正在尝试使用 Powershell SOAP 在 ServiceNow 中创建票证。我有有效的 XML,并且已使用 SoapUI 工具使用基本身份验证成功对其进行了测试。但是当我尝试通过 Powershell 将相同的 XML 发布到 ServiceNow 时,出现错误。我不确定这是否是 auth header 的问题(SoapUI 和 PS 中的相同信用)或其他问题,因为我从帖子中收到 500 错误,这听起来与 auth 无关。

使用 PS v4。长期 powershell 用户。第一次与 ServiceNow 进行 SOAP 和脚本交互。他们的 wiki 没有 powershell 示例:(
谢谢

$uri = "https://fubar.service-now.com/u_smarts_notification.do?SOAP"
$username = 'looseLips'
$password = 'sinkShips'

$xml = [xml]@"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://www.service-now.com/u_smarts_notification">
<soapenv:Header/>
<soapenv:Body>
<u:insert>
<u_assignment_group>Some Group</u_assignment_group>
<u_impact>4</u_impact>
<u_urgency>3</u_urgency>
<u_op_tier_1>Malfunction</u_op_tier_1>
<u_op_tier_2>Error</u_op_tier_2>
<u_op_tier_3>Break Fix</u_op_tier_3>
<u_short_description>Subject</u_short_description>
<u_work_notes>Body</u_work_notes>
</u:insert>
</soapenv:Body>
</soapenv:Envelope>
"@

$header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password))}
$post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml



Invoke-WebRequest : The remote server returned an error: (500) Internal Server
Error.
At R:\ps1\serviceNowINC.ps1:30 char:9
+ $post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
pWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
ll.Commands.InvokeWebRequestCommand

最佳答案

尝试设置内容类型,例如

$post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml -ContentType "application/xml"

关于适用于 ServiceNow 的 Powershell SOAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24050819/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com