I have the following code to consume Web Api and get the response.
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:44522/");
// Add an Accept header for XML format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/xml"));
IEnumerable<Product> products = new List<Product>();
HttpResponseMessage resp = client.GetAsync("api/admin").Result;
if (resp.IsSuccessStatusCode)
{
// Parse the response body.
products = resp.Content.ReadAsAsync<IEnumerable<Product>>().Result;
}
Here I am getting the products list. But instead of getting the products into a list, I want to write the response to an Xml Document.
Can somebody advise me on this?
Thanks.
You can use
ReadAsByteArrayAsync():