I wanna get xml file from http and convert it to object. So right now I made 2 methods: one two get http response body like that:
var httpClient = new HttpClient(); var op = httpClient.GetStringAsync(uri); var httpResponseBody = ""; try { var httpResponse = await httpClient.GetAsync(uri); httpResponse.EnsureSuccessStatusCode(); httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); return httpResponseBody; } ...
which returns string httpResponseBody. Second one tries to convert this xml in string to object:
res = await task; var reader = new XmlSerializer(typeof(Schedule)); using (var tr = new MemoryStream(Encoding.UTF8.GetBytes(res))) { var schedule = (Schedule)reader.Deserialize(tr); return schedule; }
The problem is that content I receive is in different encoding and I don't know how to convert it to make deserialization possible.
I am getting something like that:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ramowka><dzien name=\"PoniedziaÅ\u0082ek\" count=\"2\"/></ramowka>\n
How to get rid of '\n' and Å\u0082 (should be ł) ? Right now I am getting Exception from reader.Deserialize
: {"<ramowka xmlns=''> was not expected."}
No comments:
Post a Comment