I consume some data using fogbugz XML API. This API always offers data like UTF-8.
When using the WebClient
class to execute a request, I can set the encoding. For instance:
var result = new WebClient(); result.Encoding = Encoding.UTF8;
But what about the HttpClient
class?
HttpClient client = new HttpClient();
Should I use:
client.GetByteArrayAsync(url);
... and then convert the bytes from the encoding (UTF-8) to a string?
Or is there a way to directly get the contents as a UTF-8 string?
using (var client = Connector.GetHttpClient()) { var byteData = await client.GetByteArrayAsync(url); data = Encoding.UTF8.GetString(byteData); }
Finally, here is an excerpt from the XML response:
<?xml version="1.0" encoding="UTF-8"?> <response>
source share