Skip to content

Invoke-WebRequest does not support UTF-8 (СКУД) #5528

Description

@lipkau

@## Steps to reproduce
Assuming you have a URI that returns json and contains a non-Latin char
My sample is a Confluence wiki page which I am requesting with REST

$splatParameters = @{
              Uri             = "https://powershell.atlassian.net/wiki/rest/api/content/13009245?expand=space,version,body.storage,ancestors&limit=25"
              Method          = "GET"
              Headers         = @{
  "Accept-Charset"                = "utf-8"
  "Accept"                        = "application/json"
  "Content-Type"                  = "application/json; charset=utf-8"
  "Authorization"                 = "Basic abcd"
  }
              UseBasicParsing = $true
              ErrorAction     = 'SilentlyContinue'
          };
  Set-Content -Value (Invoke-WebRequest @splatParameters).Content -Path c:\temp\export.txt -Encoding UTF8 -force

Expected behavior

Invoke-WebRequest is able to write the file with full support of the unicode chars of the source.
In this example: Схема СКУД

Actual behavior

The REST call should return a json like this:

{"id":"13009245","type":"page","status":"current","title":"Схема СКУД","space":{....

instead, the content of c:\temp\export.txt (see example ebove) contains:

{"id":"13009245","type":"page","status":"current","title":"С�ема С�У�","space":{.....

Environment data

PS C:\Program Files\PowerShell\6.0.0-rc> $PSVersiontable

Name                           Value
----                           -----
PSVersion                      6.0.0-rc
PSEdition                      Core
GitCommitId                    v6.0.0-rc
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. markekraus commented on Nov 22, 2017

    @markekraus
    Contributor

    Oliver Lipkau (@lipkau) Have you reproduced this issue in 6.0.0-rc? This repository is for PowerShell Core issues. if you have an issue with Windows PowerShell 5.1, please use the UserVoice.

  2. lipkau commented on Nov 22, 2017

    @lipkau
    Author

    Yes... I am waiting on Joel Bennett (@Jaykul) for the $PSVersionTable (he tested it for me)

  3. lipkau commented on Nov 22, 2017

    @lipkau
    Author

    VersionTable updated

  4. markekraus commented on Nov 22, 2017

    @markekraus
    Contributor

    Since this issue has some non-latin characters in it and is accessible via an API that returns application/json the following should be an equivalent repro:

    $response = Invoke-WebRequest 'https://api.github.com/repos/PowerShell/PowerShell/issues/5528'
    Set-Content -Value $response.Content -Path c:\temp\export.txt -Encoding UTF8 -force

    When I do that, I see Схема СКУД in the file.

    Are you sure that 1) the API you are working with is actually returning UTF8 encoding and 2) the body of that content is actually encoded in utf8?

    $response.BaseResponse.Content.Headers.ContentType.CharSet
    
  5. lipkau commented on Nov 22, 2017

    @lipkau
    Author

    This seems to be a Confluence API problem.
    Closing this issue.

  6. changed the title [-]Invoke-WebRequest does not support UTF-8[/-] [+]Invoke-WebRequest does not support UTF-8 (СКУД)[/+] on Nov 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions