Hi,
More information. The output seems to differ because of the method calling the URL
$OctopusAPIKey = “your key here”
$OctopusURL = “your url here”
$Myfolder = “C:\somefolder”
OD Way
$header = @{ “X-Octopus-ApiKey” = $OctopusAPIKey }
$MyPath = $myfolder + “kris13A.xml”
$response = (Invoke-WebRequest -Uri $OctopusURL -Method Get -Headers $header).Content
[IO.File]::WriteAllLines($MyPath, $response)
My Way
$mypath2 = $Myfolder + “kris13B.xml”
$myuri = $OctopusURL + “?apikey=” + $OctopusAPIKey
$response2 = (Invoke-WebRequest -Uri $myuri -Method Get).content
[IO.File]::WriteAllLines($MyPath2, $response2)
If I grab the xml with the key in the header, like you have been doing, the file looks good.
[cid:image001.png@01D32163.66514F40]
If I grab the xml with the key in the URI, I get extra characters.
[cid:image002.png@01D32163.821DB420]
Dumping the file out with out-file or [io.file]::writealllines produces the same result.
Furthermore, and what’s strange, is that if I pipe the responses to Format-Hex and output those to a file or otherwise compare, they are the same values.
In case its relevant, I’m using PSVersion 5.0.10586.117.
I’ve also done some testing with this option
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[IO.File]::WriteAllLines($MyPath3, $response2, $Utf8NoBomEncoding)
And this seems to help get the response that comes from the url with the key in the uri into a readable format. However, this also seems to cloud the results I get when I don’t use this switch.
Anyway, I’m going to do some further testing constructing the api calls with the key in the header and see where that gets me.
Thanks for the time,
-Kris