Skip to content

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

Closed

Description

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.

Activity

  1. adamdriscoll commented on Aug 25, 2016

    @adamdriscoll
    Contributor

    This is a limitation of the .NET class that Invoke-WebRequest is using. Not sure what the best way would be to work around it.

    image

  2. rkeithhill commented on Aug 25, 2016

    @rkeithhill
    Collaborator

    File this bug/enhancement request on the CoreFx repo?

  3. thiezn commented on Aug 28, 2016

    @thiezn
    Author

    Thanks, I've raised the issue on the CoreFX repo:

    dotnet/corefx#11211

  4. added
    WG-Cmdlets
    Issue-Enhancement
    on Sep 1, 2016
  5. added
    Resolution-External
    on Oct 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-ExternalWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions