Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Using HttpClient for Rest service

$
0
0

Hi guys,

I have to consume a Rest Service, created using Asp.Net Web API (but this is not important), on a project with Xamarin iOS. I know that I can use ServiceStack or RestSharp but I want to try to use HttpClient.

To deserialise response I need to use method "ReadAsAsync" contained in "System.Net.Http.Formatting" but this It's not included in Framework. I've tried to use assembly contained in Mono 3.2.3 but I have this error:

Error CS1705: Assembly System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' referencesSystem.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version number than imported assembly `System.Net.Http, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' (CS1705)

I want to ask to you how properly use HttpClient to consume Rest Service?

I want simply to execute this code on my Xamarin.iOS app:

HttpResponseMessage response = client.GetAsync("api/products").Result; // Blocking call! if (response.IsSuccessStatusCode) { // Parse the response body. Blocking! var products = response.Content.ReadAsAsync<IEnumerable>().Result; foreach (var p in products) { Console.WriteLine("{0}\t{1};\t{2}", p.Name, p.Price, p.Category); } } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); }

I hope you help me.

Thanks!!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>