使用PowerShell解析XML POST请求中的变量
问题描述:
我试图将一个变量(日期)转换为XML文章,但是我无法使其工作。 在XML文章中,我需要指定2个日期(vndg = today和morg = today + 1)。使用PowerShell解析XML POST请求中的变量
这是我的PowerShell脚本,它的工作原理没有日期变量。
$vndg = (Get-Date).ToString("dd-MM-yyyy")
$morg = (Get-Date).AddDays(+1).ToString("dd-MM-yyyy")
[XML]$SOAP = @'
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Clocking_GetByDateRangeUtc xmlns="http://www.geodynamics.be/webservices">
<caller>
<CompanyName>companyname</CompanyName>
<LoginName>username</LoginName>
<Password>password</Password>
</caller>
<fromDateUtc>$vndg</fromDateUtc>
<toDateUtc>$morg</toDateUtc>
</Clocking_GetByDateRangeUtc>
</soap:Body>
</soap:Envelope>
'@
$headers = @{"SOAPAction" = "http://www.geodynamics.be/webservices/Clocking_GetByDateRangeUtc"}
$destination = 'C:\Temp\GeoDynamics\Downloads\GeoPers.xml'
$URI = "https://secure.geodynamics.be/webservices/intellitracer/1.0/IntegratorWebservice.asmx?WSDL"
$out = Invoke-WebRequest $uri -Method Post -ContentType 'text/xml' -Body $SOAP -Headers $headers -OutFile $destination
答
我把它通过改变脚本以下工作:
[XML]$SOAP = @"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Clocking_GetByDateRangeUtc xmlns="http://www.geodynamics.be/webservices">
<caller>
<CompanyName>name</CompanyName>
<LoginName>login</LoginName>
<Password>password</Password>
</caller>
<fromDateUtc>$vndg</fromDateUtc>
<toDateUtc>$morg</toDateUtc>
</Clocking_GetByDateRangeUtc>
</soap:Body>
</soap:Envelope>
"@
'@ '...' @' - >'@ “......” @' –
如果我这样做那么我得到一个错误==>字符串'25 -09-2017'不是有效的AllXsd值。 –
我通过改变日期变量的格式来工作==> $ vndg =(get-date).ToString(“yyyy-MM-ddT00:00:00”) $ morg =(get-date)。 AddDays(+1).ToString(“yyyy-MM-ddT00:00:00”) –