Skip to content

Invoke-RestMethod doesn't include automatic ContentType value when not using POST method #16318

@adamdriscoll

Description

@adamdriscoll

Prerequisites

Steps to reproduce

When using a POST, ContentType is automatically set to application/x-www-form-urlencoded

 invoke-restmethod https://webhook.site/6a5097af-3644-4462-9d92-d910088d2f4d -Method POST -Body @{ Test = "test" }

When using other methods, it is not. It is blank.

 invoke-restmethod https://webhook.site/6a5097af-3644-4462-9d92-d910088d2f4d -Method PUT -Body @{ Test = "test" }

image

Expected behavior

I would expect that the content type would default to form encoded for all request methods (or at least for PUT). 

Actual behavior

It is only set to form encoded for POST.

Error details

No errors.

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.0-rc.1
PSEdition                      Core
GitCommitId                    7.2.0-rc.1
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


### Visuals

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions