Skip to content

Invoke-WebRequest using Get method doesn't allow content-body #2054

@thiezn

Description

@thiezn

Making a HTTP GET requests using either Invoke-WebRequest or Invoke-RestMethod with a content-body throws an exception. HTTP RFC 7231 describes that a content-body is allowed even though the response of the webserver might be

A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.

This is making it difficult to interface with various RESTful API's like InfoBlox and ElasticSearch that rely on JSON payloads for retrieving data.

Steps to reproduce

$uri = 'http://www.microsoft.com'
$payload = @{Microsoft='loves linux'}
$result = Invoke-WebRequest -Uri $uri -Body ($payload | ConvertTo-Json) -ContentType 'application/json' -Method Get

Expected behavior

HTTP OK

Actual behavior

Invoke-WebRequest : Cannot send a content-body with this verb-type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-ExternalThe issue is caused by external component(s).WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions