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-RestMethod does not count on `Content-Type` field. Broken compared to PS 5.0. #2245

Closed
sitano opened this Issue Sep 13, 2016 · 6 comments

Comments

Projects
None yet
8 participants
@sitano
Copy link

sitano commented Sep 13, 2016

Steps to reproduce

$ Invoke-RestMethod -Uri https://httpbin.org/robots.txt                                             

Expected behavior

Return content. Or at least behave the same as in PowerShell 5.0.

Actual behavior

Invoke-RestMethod : Unexpected character encountered while parsing value: U. Path '', line 0, position 0.
At line:1 char:1

  • Invoke-RestMethod -Uri https://httpbin.org/robots.txt
  • - CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], JsonReaderException
    - FullyQualifiedErrorId : Newtonsoft.Json.JsonReaderException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    

Environment data

> $PSVersionTable
Name                           Value                                                                                                                                                                              
----                           -----                                                                                                                                                                              
PSVersion                      6.0.0-alpha                                                                                                                                                                        
PSEdition                      Core                                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                            
BuildVersion                   3.0.0.0                                                                                                                                                                            
GitCommitId                    v6.0.0-alpha.9                                                                                                                                                                     
CLRVersion                                                                                                                                                                                                        
WSManStackVersion              3.0                                                                                                                                                                                
PSRemotingProtocolVersion      2.3                                                                                                                                                                                
SerializationVersion           1.1.0.1

powershell 6.0.0-alpha.9-1

@sitano sitano changed the title Invoke-RestMethod do not rely on `Content-Type` field Invoke-RestMethod do not rely on `Content-Type` field. Broken compared to PS 5.0. Sep 13, 2016

@sitano sitano changed the title Invoke-RestMethod do not rely on `Content-Type` field. Broken compared to PS 5.0. Invoke-RestMethod does not count on `Content-Type` field. Broken compared to PS 5.0. Sep 13, 2016

@ed-ilyin

This comment has been minimized.

Copy link

ed-ilyin commented Sep 22, 2016

Exactrly same for me

@SteveL-MSFT SteveL-MSFT added this to the 6.0.0 milestone Nov 2, 2016

@nmbradford

This comment has been minimized.

Copy link
Contributor

nmbradford commented Nov 7, 2016

I have similar issues talking to an XML api. I've tried with -ContentType "application/xml" and with Content-Type set in the request header with same result in both cases. The exception I get is :

invoke-restmethod : Unexpected character encountered while parsing value: v. Path '', line 0, position 0.
At line:1 char:1
+ invoke-restmethod -method Post -headers $headerDictionary -uri $FullU ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], JsonReaderException
    + FullyQualifiedErrorId : Newtonsoft.Json.JsonReaderException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Note - Interesting that JsonReader is involved in parsing an xml response?

PS > $psversiontable

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.12-15-g92b0eb336d7af74d5e439f58ffd3a367d511c0e5
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@SteveL-MSFT SteveL-MSFT modified the milestones: 6.0.0-beta, 6.0.0 Dec 19, 2016

@chelnak

This comment has been minimized.

Copy link

chelnak commented Jan 6, 2017

We are seeing a similar issue (Logged here: jakkulabs/PowervRA#97).

The response content type is text/yaml but you can clearly see it's trying to use Newtonsofts Json library.

@joeyaiello joeyaiello referenced this issue Jan 25, 2017

Closed

PowerShell 6.0 Plan #3046

75 of 116 tasks complete

@SteveL-MSFT SteveL-MSFT self-assigned this Jan 31, 2017

@2xmax

This comment has been minimized.

Copy link
Contributor

2xmax commented Feb 7, 2017

looks like it was fixed by #2862

@joeyaiello

This comment has been minimized.

Copy link
Member

joeyaiello commented Feb 7, 2017

@2xmax: Thanks! Looks like the original issues were fixed already :)

@joeyaiello joeyaiello closed this Feb 7, 2017

@jonathanmedd

This comment has been minimized.

Copy link

jonathanmedd commented Feb 8, 2017

Excellent - thanks @2xmax ! We have been able to close one of our issues being able to support PowerShell Core thanks to your fix: jakkulabs/PowervRA#97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment