For some reason this doesn't work
Invoke-RestMethod -Uri "http://localhost" -Headers @{"Host"="web.domain.com"}
I get the error
The 'Host' header must be modified using the appropriate property or method
But I can't find the method or property on how to do this.
Thanks
You don't. You can't set HTTP headers as part of URL, it's not the way it works.
Invoke-RestMethod is perfect for quick APIs that have no special response information such as Headers or Status Codes, whereas Invoke-WebRequest gives you full access to the Response object and all the details it provides.
Description. The Invoke-RestMethod cmdlet sends HTTP and HTTPS requests to Representational State Transfer (REST) web services that return richly structured data. PowerShell formats the response based to the data type. For an RSS or ATOM feed, PowerShell returns the Item or Entry XML nodes.
This is a bug that has been fixed in PowerShell version 4.0:
C:\PS> (irm http://localhost -Headers @{Host='web.domain.com'}).html
xmlns head body
----- ---- ----
http://www.w3.org/1999/xhtml head body
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With