Getting an UTF-8 response with httpclient in Windows Store apps

后端 未结 7 2381
清酒与你
清酒与你 2020-12-10 12:44

I\'m building a Windows Store app, but I\'m stuck at getting a UTF-8 response from an API.

This is the code:

using (HttpClient client = new HttpClien         


        
7条回答
  •  清歌不尽
    2020-12-10 13:25

    Can't comment yet, so I'll have to add my thoughts here.

    You could try to use _client.GetStringAsync(url) as @cremor suggested, and set your authentication headers using the _client.DefaultRequestHeaders property. Alternatively, you could also try to use the ReadAsByteArrayAsync method on the response.Content object and use System.Text.Encoding to decode that byte array to a UTF-8 string.

提交回复
热议问题