Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Invoke-WebRequest / Invoke-RestMethod fail with an [xml] -Body argument if the document has an XML declaration but no "encoding" attribute. #19280

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.