Open 5M7X opened 3 years ago
$resp = $_.Exception.Response.GetResponseStream() this line causes a problem as GetResponseStream() seems to be deprecated since powershell v6+.
$resp = $_.Exception.Response.GetResponseStream()
I ran into this error with the latest powershell v7. A possible fix would be a wrapper like this one here: https://stackoverflow.com/a/48154663/16052146
if ($PSVersionTable.PSVersion.Major -lt 6) { if ($Error.Exception.Response) { $Reader = New-Object System.IO.StreamReader($Error.Exception.Response.GetResponseStream()) $Reader.BaseStream.Position = 0 $Reader.DiscardBufferedData() $ResponseBody = $Reader.ReadToEnd() if ($ResponseBody.StartsWith('{')) { $ResponseBody = $ResponseBody | ConvertFrom-Json } return $ResponseBody } } else { return $Error.ErrorDetails.Message } } try { $result = Invoke-WebRequest ... } catch { ParseErrorForResponseBody($_) }
Tried it out but it then breaks
710 | $reader = New-Object System.IO.StreamReader($resp)
@5M7X Have you retrieved any workaround in the meantime? Currently, facing the same issue.
$resp = $_.Exception.Response.GetResponseStream()
this line causes a problem as GetResponseStream() seems to be deprecated since powershell v6+.I ran into this error with the latest powershell v7. A possible fix would be a wrapper like this one here: https://stackoverflow.com/a/48154663/16052146
Tried it out but it then breaks
710 | $reader = New-Object System.IO.StreamReader($resp)