I’m using the code below to download this XML file:
private async static Task<string> DownloadPageAsync(string url)
{
try
{
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
handler.AllowAutoRedirect = true;
handler.UseCookies = true;
HttpClient client = new HttpClient(handler);
client.MaxResponseContentBufferSize = 10000000;
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsString();
return responseBody;
}
catch (Exception ex)
{
return "error" + ex.Message;
}
}
but the document I’m getting seems to have encoding problems. Although the document is not well formatted, I’m guessing my downloaded webpage is not in UTF-8 either. How can I return a UTF-8 string? Thanks.
your link encoding is iso-8859-1.
use
XmlDocument.Load(uriString)
or
XDocument.Load(uriString)