Appconfiguration: Invoke-WebRequest returns content as array of Integers [System.Byte]

Created on 24 Sep 2020  Â·  3Comments  Â·  Source: Azure/AppConfiguration

Hi,

When I do a Invoke-WebRequest to a URI such as "https://SomeStoreName.azconfig.io/kv?label=SomeLabel&api-version=1.0" the response "Content" contains an array of strings TypeName: System.Byte, Is this by design or a bug? If I look at the "RawContent" I see the header and the regular response I was expecting, but I really don't want to have to parse this text for my data.

Invoke-WebRequest -Uri $uri -Method GET -Headers $AppConfigHeaders -ContentType "application/json"

StatusCode : 200
StatusDescription : OK
Content : {123, 34, 105, 116…}
RawContent : HTTP/1.1 200 OK
Server: openresty/1.17.8.2
Date: Wed, 23 Sep 2020 23:02:12 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Sync-Token: zAJ0000000=0000000000000==;sn=2727261
x-ms-req…
Headers : {[Server, System.String[]], [Date, System.String[]], [Transfer-Encoding, System.String[]], [Connection, System.String[]]…}
RawContentLength : 2330
RelationLink : {}

Appreciate the help..
J

question

All 3 comments

@justinmetz It's by design. The type of Content is byte array, which is not controlled by server. As for how to decoding the byte array to string, you should check the response header Content-Type. As we can see it's utf-8, so we use UTF8 here.

$result = Invoke-WebRequest -Uri https://your-store.azconfig.io/kv/yourKey?api-version=1.0 -Headers $header
$result.Headers.'Content-Type'
   application/vnd.microsoft.appconfig.kv+json; charset=utf-8
[System.Text.Encoding]::UTF8.GetString($result.Content)

@justinmetz I hope @ZhijunZhao has answered your question. Closing.

Works great!! Thank you so much for the help..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trevonmckay picture trevonmckay  Â·  5Comments

TheReaLee picture TheReaLee  Â·  5Comments

xin9le picture xin9le  Â·  4Comments

funkysi1701 picture funkysi1701  Â·  7Comments

ssulei7 picture ssulei7  Â·  6Comments