Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-WebRequest returns content as array of Integers [System.Byte] #408

Closed
justinmetz opened this issue Sep 24, 2020 · 3 comments
Closed
Assignees
Labels

Comments

@justinmetz
Copy link

justinmetz commented Sep 24, 2020

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 justinmetz changed the title Invoke-WebRequest returns content as array of strings System.Byte Invoke-WebRequest returns content as array of Integers [System.Byte] Sep 24, 2020
@ZhijunZhao
Copy link

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

@zhenlan
Copy link
Contributor

zhenlan commented Oct 5, 2020

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

@zhenlan zhenlan closed this as completed Oct 5, 2020
@justinmetz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants