How can I fetch Response header for InvokeRest Method of Powershell Version 5, For Powershell version 6 -ResponseHeadersVariable is available , Is there any way to do it in powershell version 5. I am unable to find any way to do it.
Asked
Active
Viewed 4,515 times
2 Answers
3
I don't think there is a way to get response headers of Invoke-RestMethod
in v5 but you can easily replace that with something like
$headers = Invoke-WebRequest 'example.com' | select headers
Adding some context of your scenario can help to suggest more suitable approach.

Denys Denysenko
- 7,598
- 1
- 20
- 30
-
Thanks @Denys, Invoke-WebRequest method worked, Actually i was searching for Invoke-RestMethod only that's why could't find any thing. Again Thanks!!!! – Sakshi Rawal Oct 03 '18 at 06:50
1
I am using powershell core and Invoke-RestMethod now has a parameter for getting response headers.
♥ pwsh::github$ $null = Invoke-RestMethod -Uri https://google.com -ResponseHeadersVariable rh
♥ pwsh::github$ $rh
Key Value
--- -----
Date {Tue, 15 Aug 2023 21:43:50 GMT}
Cache-Control {max-age=0, private}
Content-Security-Policy-Report-Only {object-src 'none';base-uri 'self';script
...........