Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thiezn opened this issue Aug 25, 2016 · 3 comments
Closed

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

thiezn opened this issue Aug 25, 2016 · 3 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-External The issue is caused by external component(s). WG-Cmdlets general cmdlet issues

Comments

@thiezn
Copy link

thiezn commented Aug 25, 2016

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.

@adamdriscoll
Copy link
Contributor

adamdriscoll commented Aug 25, 2016

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

@rkeithhill
Copy link
Collaborator

rkeithhill commented Aug 25, 2016

File this bug/enhancement request on the CoreFx repo?

@thiezn
Copy link
Author

thiezn commented Aug 28, 2016

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

dotnet/corefx#11211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-External The issue is caused by external component(s). WG-Cmdlets general cmdlet issues
Projects
None yet
Development

No branches or pull requests

4 participants