Invoke-WebRequest should rewind the RawContentStream - by Joel 'Jaykul' Bennett

Status : 

 


5
0
Sign in
to vote
ID 807797 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 11/5/2013 11:08:51 AM
Access Restriction Public

Description

The object that's output from Invoke-WebRequest has a "RawContentStream" which is a memory stream that has a copy of the network stream received in the response.  However, it's pointer is left at the end of the stream (where it naturally is, after the content has been copied), which means that anyone wanting to read the stream has to first seek the stream to the beginning.

Invoke-WebRequest should move the location to the beginning of the stream before returning, to make it easier to use the stream from Powershell (avoiding this):

$null = $WebResponse.RawContentStream.Seek(0,"Begin")

There's virtually no risk to fixing it, since basically every possible use of that stream currently requires resetting it, and resetting it twice wouldn't hurt anything anyway.
Sign in to post a comment.