Error using HTTPClient examples: Task does not contain a definition for 'Content'

System.Threading.Tasks.Task does not contain a definition for 'Content'

Hi - I am trying to run this code

var client = new System.Net.Http.HttpClient ();
            client.DefaultRequestHeaders.Add("Accept", "application/json");
            var address = $"http://localhost/yii2/basic/web/api/v1/t/next"; //?format=application/json";

            var response = client.GetAsync(address);

            var airportJson = response.Content.ReadAsStringAsync().Result;

As per the examples given here:

https://github.com/conceptdev/xamarin-forms-samples/blob/master/HttpClient/HttpClientDemo/Airports/AirportsPage.xaml.cs

However - I get this error in IDE on the last line where I am calling -> response.Content

Any guidance will be helpful.

Thanks

Posts

  • AbhijitRaiAbhijitRai USMember

    Never mind - I figured it out. For anyone else having the same issue - the only way I got around to it is by putting the code in a separate async method.

Sign In or Register to comment.