我正在尝试将一个变量(日期)转到XML帖子中,但我无法使其工作。在XML帖子中,我需要指定2个日期(VNDG =今天,Morg =今天 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:TempGeoDynamicsDownloadsGeoPers.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>
"@