Invoke-WebRequest ignores content encoding - by Joel 'Jaykul' Bennett

Status : 


Sign in
to vote
ID 807794 Comments
Status Active Workarounds
Type Bug Repros 2
Opened 11/5/2013 10:51:28 AM
Access Restriction Public


Invoke-WebRequest is leaving byte-order marks (BOM) in the Content.

For example, this file:

If I fetch it with WebClient.DownloadString I get the content I expected, but when I fetch it with Invoke-WebRequest, I end up with the byte-order mark in the first few bytes of the Content property (which prevents me from parsing the string as XML or PowerShell etc.). 

If I use Invoke-WebRequest -Outfile (or manually write the Content property with the BOM into a file), I can Get-Content on the file and the BOM is gone, because Get-Content absorbs it correctly.

The root cause of the problem seems to be that when the stream is read, PowerShell isn't using the specified encoding (the CharacterSet specified in the Response Header).
Sign in to post a comment.