Invoke-Webrequest Encoding RRS feed

  • Question

  • Hi all,

    I have been playing around with the API on my Phillips HUE.

    My problem is with encoding of the response. I live in Denmark where we use speciel charecters ÆØÅ.

    When i use Invoke-WebRequest or Invoke-RestMethod the ÆØÅ are not formatted correctly. When i tap in to .Net directly it works as exspected:

    $splatParameters = @{
        Uri             = "$($site)sensors/8"
        Method          = "GET"
        Headers         = @{
    "Accept-Charset"                = "utf-8"
    "Accept"                        = "application/json"
    "Content-Type"                  = "application/json; charset=utf-8"
        UseBasicParsing = $true
        ErrorAction     = 'SilentlyContinue'
    $test = Invoke-WebRequest @splatParameters

    The response:

    {"state":{"flag":false,"lastupdated":"none"},"config":{"on":true,"reachable":true},"name":"Wake up sovev??relse","type":"CLIPGenericFlag","modelid":"WAKEUP","manufacturername":"Philips","swversion":"1.0","uniqueid":"L_04_GSoTj","recycle":true}

    When i try the .Net:

    $req = [System.Net.WebRequest]::Create("$($site)sensors/8")
    $req.ContentType = "application/json; charset=utf-8"
    $req.Accept = "application/json"
    $resp = $req.GetResponse()
    $reader = new-object System.IO.StreamReader($resp.GetResponseStream())
    $test1 = $reader.ReadToEnd()

    The response:

    {"state":{"flag":false,"lastupdated":"none"},"config":{"on":true,"reachable":true},"name":"Wake up soveværelse","type":"CLIPGenericFlag","modelid":"WAKEUP","manufacturername":"Philips","swversion":"1.0","uniqueid":"L_04_GSoTj","recycle":true}

    Am i doing something wrong?

    Sunday, March 18, 2018 5:44 PM


All replies