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
@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..