I used WebClient to get the Xml object from the restfull service (.net web api) and everything worked fine:
using(WebClient client = new WebClient())
{
client.Encoding = UTF8Encoding.UTF8;
client.Headers[HttpRequestHeader.ContentType] = "text/xml";
client.Credentials =
xmlResult = webClient.DownloadString(url);
}
....
this code works great. I get Xml as a string back, everyone is happy.
Now I changed it to work with HttpClient, and I cannot get the returned Xml - always json as a string.
using(var handler = new HttpClientHandler() {Credentials = new NetworkCredentials})
using(var client = new HttpClient(handler))
{
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(HttpRequestHeader.ContentType.ToString(), "text/xml");
returnedXml = client.SendAsync(request).Result.Content.ReadAsStringAsync().Result;
}
What am I doing wrong? How can I get the Xml I want?
thank
source
share