【发布时间】:2018-03-06 06:49:33
【问题描述】:
我正在尝试将变量(日期)放入 XML 帖子中,但我无法让它工作。 在 XML 帖子中,我需要指定 2 个日期(vndg=today 和 morg=today+1)。
这是我的 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
【问题讨论】:
-
@'...'@->@"..."@ -
如果我这样做了,我会得到一个错误 ==> 字符串 '25-09-2017' 不是有效的 AllXsd 值。
-
我通过更改日期变量的格式使其工作 ==> $vndg = (get-date).ToString("yyyy-MM-ddT00:00:00") $morg = ( get-date).AddDays(+1).ToString("yyyy-MM-ddT00:00:00")
-
(Get-Date).Date.ToString('s')
标签: xml powershell variables soap