Skip to content

Breaking change: Invoke-WebRequest -ContentType with empty string now fails #11396

@jazzdelightsme

Description

@jazzdelightsme

Steps to reproduce

Unfortunately I don't have a simple repro at hand, but the change is that passing an empty string for the -ContentType parameter of Invoke-WebRequest used to work, through 6.2.3, but now it fails.

I'm using a popular internal module that makes calls to the Azure DevOps web service. It has an internal function that accepts a [string] $ContentType parameter, which then gets passed on to Invoke-WebRequest. When there is no body to send, and thus no content type, the calling code passes $null for $ContentType, but since the parameter type is [string], it gets converted to an empty string. The same thing happens in PS5.1. In PS5.1, passing in the empty string works (it treats it as no content type), and the same in PsCore 6. But on PSv7:

Actual behavior

The cmdlet cannot run because the -ContentType parameter is not a valid Content-Type header. Specify a valid Content-Type for -ContentType, then retry. To suppress header validation, supply the -SkipHeaderValidation parameter.

Expected behavior

(no error)

I don't know if this is worth breaking the glass on the RC, but at a minimum, because this is a heavily-used, workhorse cmdlet, I think it should be documented.

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-Changebreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-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