lundi 22 août 2016

How to check if response header contains certain headers powershell

I'm using iwr to make a request like so:

iwr "http://someapi/param" -UseBasicParsing -Method Head

This gets me the headers which looks something like this:

$var1 = "Timing-Allow-Origin: *
X-CID: 1
Accept-Ranges: bytes
Content-Length: 43
Cache-Control: public,max-age=172800
Content-Type: image/gif
Other headers

How do I check if the headers contain this:

"Timing-Allow-Origin"="*"
"Cache-Control"="public,max-age=172800"

I tried

$var2 = iwr "http://someapi/param" -UseBasicParsing -Method Head
Write-Host ($var2 -like "*Timing-Allow-Origin: *")

But this returns false for some reason. Is there a way to do this?

Aucun commentaire:

Enregistrer un commentaire