I'm consuming some data using the fogbugz XML API. This API always offers data as UTF-8.
When using the WebClient
class for making a request I am able to set the encoding. For example:
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 content 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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…