Home Dashboard Directory Help
Search

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


Status: 

Active


11
0
Sign in
to vote
Type: Bug
ID: 807794
Opened: 11/5/2013 10:51:28 AM
Access Restriction: Public
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

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

For example, this file: http://poshcode.org/Modules/Reflection.psd1

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).
Details
Sign in to post a comment.
Sign in to post a workaround.