Prerequisites
Steps to reproduce
Said cmdlets try to glean the desired encoding from the encoding attribute of an [xml] instance's XML declaration.
However, it is possible to have an XML declaration without such an attribute, which unexpectedly causes an error, because the code seemingly makes the assumption that this attribute is always there:
# Note: If you remove the XML declaration or add a valid "encoding" attribute, the problem goes away.
Invoke-RestMethod https://postman-echo.com/post -Method POST -ContentType text/xml -Body ([xml] '<?xml version="1.0"?><foo/>')
Expected behavior
The call should succeed and output a [pscustomobject] instance.
Actual behavior
The call fails with the following error:
Invoke-RestMethod: '' is not a supported encoding name. [...]
Error details
No response
Environment data
PowerShell Core 7.4.0-preview.1
Visuals
No response